@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.
Files changed (45) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/bin/activate.js +1 -2
  3. package/bin/deploy/index.js +3 -2
  4. package/bin/deploy/to-sqlite.js +2 -2
  5. package/bin/extend.js +2 -4
  6. package/bin/help.js +1 -1
  7. package/bin/import.js +105 -23
  8. package/bin/login.js +7 -8
  9. package/bin/logout.js +1 -2
  10. package/bin/repl.js +1 -1
  11. package/bin/watch.js +30 -11
  12. package/lib/client/activate.js +243 -0
  13. package/lib/client/auth_manager.js +115 -0
  14. package/lib/client/base_command.js +55 -0
  15. package/lib/client/extend.js +179 -0
  16. package/lib/client/helper/cf_helper.js +186 -0
  17. package/lib/client/helper/dependency_helper.js +26 -0
  18. package/lib/client/helper/env_helper.js +4 -0
  19. package/lib/client/helper/fs_helper.js +83 -0
  20. package/lib/client/helper/logging.js +37 -0
  21. package/lib/client/helper/question.js +50 -0
  22. package/lib/client/helper/string_helper.js +53 -0
  23. package/lib/client/helper/url_helper.js +17 -0
  24. package/lib/client/index.js +14 -0
  25. package/lib/client/params.js +435 -0
  26. package/lib/client/settings_manager.js +526 -0
  27. package/lib/import/common.js +24 -1
  28. package/lib/import/importapi.js +1 -1
  29. package/lib/import/index.js +25 -41
  30. package/lib/import/message.js +10 -6
  31. package/lib/import/v2parser.js +301 -47
  32. package/lib/import/v4parser.js +391 -71
  33. package/lib/init/constants.js +1 -1
  34. package/lib/init/index.js +15 -10
  35. package/lib/init/template/data/index.js +38 -46
  36. package/lib/init/template/hana/index.js +2 -2
  37. package/lib/init/template/lint/index.js +8 -6
  38. package/lib/init/template/mta/projectReader.js +8 -5
  39. package/lib/init/template/nodejs/files/.vscode/extensions.json +1 -1
  40. package/lib/init/template/nodejs/index.js +1 -8
  41. package/lib/lint/Linter.js +62 -60
  42. package/lib/lint/generators.js +1 -1
  43. package/lib/lint/io.js +9 -33
  44. package/npm-shrinkwrap.json +5179 -10848
  45. package/package.json +5 -5
@@ -6,13 +6,21 @@
6
6
  'use strict';
7
7
 
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 = {};
12
13
  let enumTypes = {};
14
+ let typeDefinitions = {};
15
+ let unboundedActions = {};
16
+ let boundedActions = {};
17
+ let unboundedFunctions = {};
18
+ let boundedFunctions = {};
13
19
  let errors = [];
14
20
  let Multimap = require('../import/utils/MultiMap.js');
15
21
  let entitySetToEntityTypeMap = new Multimap();
22
+ let actionImportToActionMap = new Multimap();
23
+ let functionImportToFunctionMap = new Multimap();
16
24
  let validEdmDatatypes = ['Edm.DateTimeOffset'];
17
25
  let jsonEntityContainerName;
18
26
  const ignoreObjects = ['$Reference']; // add all the objects that needs to be ignored for parsing.
@@ -145,6 +153,12 @@ function _generateComplexTypePropertyCsn(propertyType) {
145
153
  return property;
146
154
  }
147
155
 
156
+ function _generateTypeDefinitionPropertyCsn(propertyType) {
157
+ let property = {};
158
+ property.type = propertyType.$Type;
159
+ return property;
160
+ }
161
+
148
162
  function _parseAssociationProperty(foreignReference, associationNode, mockServerUc) {
149
163
  let associationProperty = {};
150
164
  let foreignKeys;
@@ -154,6 +168,7 @@ function _parseAssociationProperty(foreignReference, associationNode, mockServer
154
168
  let data;
155
169
  let ref;
156
170
  associationProperty.type = 'cds.Association';
171
+ associationProperty.doc = 'Please add an ON condition\n';
157
172
  // associationProperty.target = associationNode.$Type;
158
173
  if (mockServerUc && entitySetToEntityTypeMap && entitySetToEntityTypeMap.get(associationNode.$Type)) {
159
174
  if (entitySetToEntityTypeMap.get(associationNode.$Type).length > 1) {
@@ -197,11 +212,16 @@ function _parseAssociationProperty(foreignReference, associationNode, mockServer
197
212
  associationProperty.on.push(' and ');
198
213
  }
199
214
  }
215
+ }
216
+ // Convert managed associations and compositions in unmanaged with empty key to avoid
217
+ // "generation" of keys, that do not exist in the external service.
218
+ if (common.checkForEmptyKeys(associationProperty, "V4")) {
219
+ associationProperty.keys = [];
200
220
  }
201
221
  return associationProperty;
202
222
  }
203
223
 
204
- function _generateCSNForEntityType(entityTypes, ignorePersistenceSkip, mockServerUc) {
224
+ function _generateCSNForEntityType(entityTypes, mockServerUc) {
205
225
  let entityCsn = {};
206
226
  let keySet;
207
227
  let curKey;
@@ -215,9 +235,6 @@ function _generateCSNForEntityType(entityTypes, ignorePersistenceSkip, mockServe
215
235
  if (key) {
216
236
  entityCsn[key] = {};
217
237
  entityCsn[key].kind = 'entity';
218
- if (!ignorePersistenceSkip) {
219
- entityCsn[key]['@cds.persistence.skip'] = true;
220
- }
221
238
  // inheritance
222
239
  if (baseType) {
223
240
  entityCsn[key].includes = [];
@@ -258,6 +275,10 @@ function _generateCSNForEntityType(entityTypes, ignorePersistenceSkip, mockServe
258
275
  } else if (element[key][property].$Kind === 'NavigationProperty') {
259
276
  entityCsn[key].elements[property] = _parseAssociationProperty(property,
260
277
  element[key][property], mockServerUc);
278
+ } else if (typeDefinitions[element[key][property].$Type]){
279
+ // for TypeDefinitions
280
+ propertyType = element[key][property];
281
+ entityCsn[key].elements[property] = _generateTypeDefinitionPropertyCsn(propertyType);
261
282
  }
262
283
  }
263
284
  }
@@ -305,17 +326,16 @@ function _generateEntityType(entityTypes, schemaData, mockServerUc) {
305
326
  });
306
327
  }
307
328
 
308
- function _parseEntityType(schemaDataList, ignorePersistenceSkip, mockServerUc) {
329
+ function _parseEntityType(schemaDataList, mockServerUc) {
309
330
  // collect entity types
310
331
  let entityTypes = [];
311
332
  let schemaData;
312
- let i = 0;
313
- for (i = 0; i < schemaDataList.length; i++) {
333
+ for (let i = 0; i < schemaDataList.length; i++) {
314
334
  schemaData = schemaDataList[i];
315
335
  _generateEntityType(entityTypes, schemaData, mockServerUc);
316
336
  }
317
337
  // parse it
318
- return _generateCSNForEntityType(entityTypes, ignorePersistenceSkip, mockServerUc);
338
+ return _generateCSNForEntityType(entityTypes, mockServerUc);
319
339
  }
320
340
 
321
341
  function _generateEnumType(schemaData) {
@@ -333,16 +353,167 @@ function _generateEnumType(schemaData) {
333
353
  }
334
354
 
335
355
  function _collectEnumType(schemaDataList) {
336
- // collect complex types
337
356
  let schemaData;
338
- let i = 0;
339
- for (i = 0; i < schemaDataList.length; i++) {
357
+ for (let i = 0; i < schemaDataList.length; i++) {
340
358
  schemaData = schemaDataList[i];
341
359
  enumTypes = _generateEnumType(schemaData);
342
360
  }
343
361
  return enumTypes;
344
362
  }
345
363
 
364
+ function _generateTypeDefinition(schemaData) {
365
+ let typeDefDict = {};
366
+ let temp;
367
+ Object.keys(schemaData).forEach(curTypeDef => {
368
+ if (schemaData[curTypeDef] instanceof Object) {
369
+ if (schemaData[curTypeDef].$Kind && schemaData[curTypeDef].$Kind === 'TypeDefinition') {
370
+ temp = namespace + '.' + curTypeDef;
371
+ typeDefDict[temp] = schemaData[curTypeDef];
372
+ }
373
+ }
374
+ });
375
+ return typeDefDict;
376
+ }
377
+
378
+ function _collectTypeDefinition(schemaDataList) {
379
+ let schemaData;
380
+ for (let i = 0; i < schemaDataList.length; i++) {
381
+ schemaData = schemaDataList[i];
382
+ typeDefinitions = _generateTypeDefinition(schemaData);
383
+ }
384
+ }
385
+
386
+ function _generateBounded(schemaData, flag) {
387
+ let bFunction = {};
388
+ let boundedFunction = [];
389
+ let temp;
390
+ let kindString;
391
+ if (flag == 1) {
392
+ kindString = 'Function';
393
+ }
394
+ else {
395
+ kindString = 'Action';
396
+ }
397
+ Object.keys(schemaData).forEach(curFunction => {
398
+ if (schemaData[curFunction] instanceof Array && schemaData[curFunction][0].$Kind === kindString && schemaData[curFunction][0].$IsBound === true) {
399
+ boundedFunction = [];
400
+ temp = namespace + '.' + curFunction;
401
+ for (let i = 0; i < schemaData[curFunction].length; i++) {
402
+ boundedFunction.push(schemaData[curFunction][i]);
403
+ bFunction[temp] = boundedFunction;
404
+ }
405
+ }
406
+ });
407
+ return bFunction;
408
+ }
409
+
410
+ function _collectBounded(schemaDataList, flag) {
411
+ let schemaData;
412
+ for (let i = 0; i < schemaDataList.length; i++) {
413
+ schemaData = schemaDataList[i];
414
+ if (flag == 0) {
415
+ boundedActions = _generateBounded(schemaData, 0);
416
+ }
417
+ else {
418
+ boundedFunctions = _generateBounded(schemaData, 1);
419
+ }
420
+ }
421
+ }
422
+
423
+ function _parseBounded(csnDefs, flag) {
424
+ let boundedEdmxKind, boundedObj, boundedCsnKind, boundedEntityName, obj, paramType, paramName, paramObj, name, returnType;
425
+ if (flag == 0) {
426
+ boundedEdmxKind = "Action";
427
+ boundedCsnKind = "action";
428
+ boundedObj = boundedActions;
429
+ }
430
+ else {
431
+ boundedEdmxKind = "Function";
432
+ boundedCsnKind = "function";
433
+ boundedObj = boundedFunctions;
434
+ }
435
+ if (Object.keys(boundedObj).length > 0) {
436
+ Object.keys(boundedObj).forEach(b => {
437
+ for (let j = 0; j < boundedObj[b].length; j++) {
438
+ if (boundedObj[b][j].$Kind === boundedEdmxKind) {
439
+ name = b.substring(b.lastIndexOf(".") + 1);
440
+ obj = boundedObj[b];
441
+ boundedEntityName = obj[j].$Parameter[0].$Type;
442
+ if (csnDefs[boundedEntityName] === undefined) {
443
+ boundedEntityName = namespace + "." + entitySetToEntityTypeMap.get(boundedEntityName)[0];
444
+ }
445
+ if (csnDefs[boundedEntityName]) {
446
+ if (csnDefs[boundedEntityName].actions === undefined)
447
+ csnDefs[boundedEntityName].actions = {};
448
+ csnDefs[boundedEntityName].actions[name] = {};
449
+ csnDefs[boundedEntityName].actions[name].kind = boundedCsnKind;
450
+ // add params
451
+ if (obj[j].$Parameter && obj[j].$Parameter.length >= 2) {
452
+ /**
453
+ * 1. Considering length >= 2 because we need to consider from the 2nd
454
+ * parameter onwards. 1st parameter only tells which entity is this
455
+ * action/function bounded to and that parameter is no where used
456
+ * to retrieve any data during service runtime. So skipping it and
457
+ * the details of 1st parameter will not be preserved in the csn.
458
+ * 2. The 1st parameter will be reflected back as parameter name "in"
459
+ * during csn to edmx conversion by the compiler.
460
+ * */
461
+ csnDefs[boundedEntityName].actions[name].params = {};
462
+ for (let i = 1; i < obj[j].$Parameter.length; i++) {
463
+ paramObj = obj[j].$Parameter[i];
464
+ paramName = obj[j].$Parameter[i].$Name;
465
+ // check if the parameter type is pre-defined, undefined or custom defined
466
+ if (edmxncdsdatatype[paramObj.$Type])
467
+ paramType = generatePropertyCsn(paramObj, false);
468
+ else if (paramObj.$Type === undefined)
469
+ paramType = { "type": "cds.LargeString" }; // intentionally used LargeString
470
+ else {
471
+ if (entitySetToEntityTypeMap.get(obj[j].$Parameter[i].$Type)) {
472
+ let type = namespace + "." + entitySetToEntityTypeMap.get(obj[j].$Parameter[i].$Type)[0];
473
+ paramType = { "type": type };
474
+ }
475
+ else {
476
+ paramType = { "type": obj[j].$Parameter[i].$Type };
477
+ }
478
+ }
479
+ // check if parameter type is a collection
480
+ if (paramObj.$Collection) {
481
+ csnDefs[boundedEntityName].actions[name].params[paramName] = {};
482
+ csnDefs[boundedEntityName].actions[name].params[paramName].items = paramType;
483
+ } else
484
+ csnDefs[boundedEntityName].actions[name].params[paramName] = paramType;
485
+ }
486
+ }
487
+ // add returns
488
+ if (obj[j].$ReturnType) {
489
+ csnDefs[boundedEntityName].actions[name].returns = {};
490
+ // check if the return type is pre-defined, undefined or custom defined
491
+ if (edmxncdsdatatype[obj[j].$ReturnType.$Type])
492
+ returnType = generatePropertyCsn(obj[j].$ReturnType, false);
493
+ else if (obj[j].$ReturnType.$Type === undefined)
494
+ returnType = { "type": "cds.LargeString" }; // intentionally used LargeString
495
+ else {
496
+ if (entitySetToEntityTypeMap.get(obj[j].$ReturnType.$Type) && entitySetToEntityTypeMap.get(obj[j].$ReturnType.$Type)[0]) {
497
+ let type = namespace + "." + entitySetToEntityTypeMap.get(obj[j].$ReturnType.$Type)[0];
498
+ returnType = { "type": type };
499
+ }
500
+ else {
501
+ returnType = { "type": obj[j].$ReturnType.$Type };
502
+ }
503
+ }
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
+ }
510
+ }
511
+ }
512
+ }
513
+ });
514
+ }
515
+ }
516
+
346
517
  function _generateComplexType(schemaData) {
347
518
  let complexTypeDict = {};
348
519
  let temp;
@@ -360,8 +531,7 @@ function _generateComplexType(schemaData) {
360
531
  function _collectComplexType(schemaDataList) {
361
532
  // collect complex types
362
533
  let schemaData;
363
- let i = 0;
364
- for (i = 0; i < schemaDataList.length; i++) {
534
+ for (let i = 0; i < schemaDataList.length; i++) {
365
535
  schemaData = schemaDataList[i];
366
536
  complexTypes = _generateComplexType(schemaData);
367
537
  }
@@ -399,10 +569,116 @@ function _generateCSNForComplexType(schemaData) {
399
569
  return complexCsn;
400
570
  }
401
571
 
402
- function _generateCSN(edmxAsJson, ignorePersistenceSkip, mockServerUc) {
572
+ function _parseTypeDefinition() {
573
+ let typeDef = {};
574
+ let propertyType;
575
+ Object.keys(typeDefinitions).forEach(element => {
576
+ typeDef[element] = {};
577
+ typeDef[element].kind = 'type';
578
+ if (!typeDefinitions[element].$Type || edmxncdsdatatype[typeDefinitions[element].$Type]) {
579
+ propertyType = typeDefinitions[element];
580
+ typeDef[element] = Object.assign(typeDef[element], generatePropertyCsn(propertyType, false));
581
+ }
582
+ });
583
+ return typeDef;
584
+ }
585
+
586
+ function _parseUnbounded(schemaData, flag) {
587
+ let unboundedObj = {}, unbounded, unboundedCsnKind;
588
+ let importToMap = new Multimap();
589
+ if (flag == 0) {
590
+ unbounded = unboundedActions;
591
+ importToMap = actionImportToActionMap;
592
+ unboundedCsnKind = "action";
593
+ }
594
+ else {
595
+ unbounded = unboundedFunctions;
596
+ importToMap = functionImportToFunctionMap;
597
+ unboundedCsnKind = "function";
598
+ }
599
+ if (Object.keys(unbounded).length > 0) {
600
+ Object.keys(unbounded).forEach(ub => {
601
+ let obj = {};
602
+ let objType = {}, objData = {}, temp;
603
+ if (importToMap && importToMap.get(ub)) {
604
+ temp = importToMap.get(ub)[0];
605
+ objType = namespace + "." + temp;
606
+ objData = schemaData[0][temp][0];
607
+ obj[objType] = {};
608
+ obj[objType].kind = unboundedCsnKind;
609
+ // add params
610
+ if (objData.$Parameter && objData.$Parameter.length > 0) {
611
+ obj[objType].params = {};
612
+ let type;
613
+ let typeProperties = {};
614
+ for (let i = 0; i < objData.$Parameter.length; i++) {
615
+ obj[objType].params[objData.$Parameter[i].$Name] = {};
616
+ // check if the parameter type is pre-defined, undefined or custom defined
617
+ if (edmxncdsdatatype[objData.$Parameter[i].$Type]) {
618
+ const parameterProperties = generatePropertyCsn(objData.$Parameter[i], false);
619
+ ({type, ...typeProperties} = parameterProperties);
620
+ }
621
+ else if (objData.$Parameter[i].$Type === undefined) {
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
+ }
630
+
631
+ // Adds type properties like scale, precision, etc if any
632
+ const parameterObj = Object.keys(typeProperties).length > 0 ? { type, ...typeProperties } : { type };
633
+
634
+ // check if parameter type is a collection
635
+ if (objData.$Parameter[i].$Collection)
636
+ obj[objType].params[objData.$Parameter[i].$Name].items = parameterObj;
637
+ else
638
+ obj[objType].params[objData.$Parameter[i].$Name] = parameterObj;
639
+ }
640
+ }
641
+ // add returns
642
+ if (objData.$ReturnType && Object.keys(objData.$ReturnType).length > 0 && obj) {
643
+ obj[objType].returns = {};
644
+ let returnValue;
645
+ // check if the return type is pre-defined, undefined or custom defined
646
+ if (edmxncdsdatatype[objData.$ReturnType.$Type]) {
647
+ returnValue = generatePropertyCsn(objData.$ReturnType, false);
648
+ }
649
+ else if (objData.$ReturnType.$Type === undefined) {
650
+ returnValue = { "type": "cds.LargeString" }; // intentionally used LargeString
651
+ }
652
+ else {
653
+ if (entitySetToEntityTypeMap.get(objData.$ReturnType.$Type) && entitySetToEntityTypeMap.get(objData.$ReturnType.$Type)[0]) {
654
+ let type = namespace + "." + entitySetToEntityTypeMap.get(objData.$ReturnType.$Type)[0];
655
+ returnValue = { "type": type };
656
+ }
657
+ else
658
+ returnValue = { "type": objData.$ReturnType.$Type };
659
+ }
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
+ }
667
+ }
668
+ unboundedObj = Object.assign(unboundedObj, obj);
669
+ });
670
+ }
671
+ return unboundedObj;
672
+ }
673
+
674
+ function _generateCSN(edmxAsJson, mockServerUc) {
403
675
  let schemaCounter = 0;
404
676
  let csn = {};
405
677
  let schemaData = [];
678
+ unboundedActions = {};
679
+ boundedActions = {};
680
+ unboundedFunctions = {};
681
+ boundedFunctions = {};
406
682
  csn.meta = {};
407
683
  csn.meta.creator = 'cds-dk ' + versionInfo;
408
684
  csn.$version = '2.0';
@@ -421,6 +697,14 @@ function _generateCSN(edmxAsJson, ignorePersistenceSkip, mockServerUc) {
421
697
  if (ignoreObjects.indexOf(data) === -1 && entityContainer[data] instanceof Object &&
422
698
  entityContainer[data].$Type && entityContainer[data].$Collection) {
423
699
  entitySetToEntityTypeMap.set(entityContainer[data].$Type, data);
700
+ } else if (ignoreObjects.indexOf(data) === -1 && entityContainer[data] instanceof Object &&
701
+ entityContainer[data].$Action) {
702
+ actionImportToActionMap.set(entityContainer[data].$Action, data);
703
+ unboundedActions[entityContainer[data].$Action] = entitySetData[data];
704
+ } else if (ignoreObjects.indexOf(data) === -1 && entityContainer[data] instanceof Object &&
705
+ entityContainer[data].$Function) {
706
+ functionImportToFunctionMap.set(entityContainer[data].$Function, data);
707
+ unboundedFunctions[entityContainer[data].$Function] = entitySetData[data];
424
708
  }
425
709
  });
426
710
  }
@@ -437,74 +721,113 @@ function _generateCSN(edmxAsJson, ignorePersistenceSkip, mockServerUc) {
437
721
  errors.push(errorMsg);
438
722
  // throw errorMsg;
439
723
  }
440
- // Step 1: get all complex types.
724
+
441
725
  csn.definitions[namespace] = {};
442
726
  csn.definitions[namespace].kind = 'service';
727
+ csn.definitions[namespace]['@cds.external'] = true;
728
+
443
729
  _collectEnumType(schemaData);
730
+ _collectTypeDefinition(schemaData);
731
+ _collectBounded(schemaData, 0);
732
+ _collectBounded(schemaData, 1);
733
+
734
+ // Step 1: get all complex types.
444
735
  csn.definitions = Object.assign(_generateCSNForComplexType(schemaData), csn.definitions);
445
- // Step 2: Parsing entity type
446
- csn.definitions = Object.assign(_parseEntityType(schemaData, ignorePersistenceSkip, mockServerUc), csn.definitions);
447
- _generateDocumentation(schemaData,csn.definitions);
736
+ // Step 2: get all type definition
737
+ csn.definitions = Object.assign(_parseTypeDefinition(), csn.definitions);
738
+ // Step 3: get all unbounded action & function
739
+ csn.definitions = Object.assign(_parseUnbounded(schemaData, 0), csn.definitions);
740
+ csn.definitions = Object.assign(_parseUnbounded(schemaData , 1), csn.definitions);
741
+ // Step 4: get all entity type
742
+ csn.definitions = Object.assign(_parseEntityType(schemaData, mockServerUc), csn.definitions);
743
+ // Step 5: get all bounded action & function
744
+ _parseBounded(csn.definitions, 0);
745
+ _parseBounded(csn.definitions, 1);
746
+ // Step 6: get all annotations
747
+ _generateDocumentation(schemaData, csn.definitions);
748
+
448
749
  return JSON.stringify(csn, null, 4);
449
750
  }
450
751
 
451
- function _generateDocumentation(schemaData,cdsDefs){
452
-
453
- Object.entries(schemaData[0].$Annotations).map(annotation => {
454
- let flag;
455
- // eslint-disable-next-line no-prototype-builtins
456
- if (annotation[1].hasOwnProperty('@Core.Description')) {
457
- flag = true;
458
- if(annotation[0].indexOf('/') === -1){
459
- if(annotation[0].endsWith(".EntityContainer")){
460
- let path = annotation[0].split(".")[0];
461
- cdsDefs[path].doc = annotation[1]["@Core.Description"];
462
- }
463
- if(cdsDefs[annotation[0]]){
464
- cdsDefs[annotation[0]].doc = annotation[1]["@Core.Description"];
752
+ function _removeCarriageReturn(text) {
753
+ return text.replace(/(?:\\[rn]|[\r\n]+)+/gm, "\n").replace(/\s+/g, ' ').trim();
754
+ }
755
+
756
+ function _generateDocumentation(schemaData, cdsDefs) {
757
+ if (schemaData[0].$Annotations) {
758
+ Object.entries(schemaData[0].$Annotations).map(annotation => {
759
+ let flag;
760
+ // eslint-disable-next-line no-prototype-builtins
761
+ if (annotation[1].hasOwnProperty('@Core.Description')) {
762
+ flag = true;
763
+ if (annotation[0].indexOf('/') === -1) {
764
+ if (annotation[0].endsWith(".EntityContainer")) {
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
+ }
465
779
  }
466
- }else{
467
- let path = annotation[0].split('/');
468
- if(cdsDefs[path[0]]["elements"][path[1]]){
469
- cdsDefs[path[0]]["elements"][path[1]].doc = annotation[1]["@Core.Description"];
470
- }
471
- }}
472
- // eslint-disable-next-line no-prototype-builtins
473
- if (annotation[1].hasOwnProperty('@Core.LongDescription') ) {
474
- if(annotation[0].indexOf('/') === -1){
475
- if(annotation[0].endsWith(".EntityContainer")){
780
+ }
781
+ // eslint-disable-next-line no-prototype-builtins
782
+ if (annotation[1].hasOwnProperty('@Core.LongDescription')) {
783
+ if (annotation[0].indexOf('/') === -1) {
784
+ if (annotation[0].endsWith(".EntityContainer")) {
476
785
  let path = annotation[0].split(".")[0];
477
- if(flag === true){
478
- cdsDefs[path].doc += "\n\n ";
786
+ if (flag === true) {
787
+ cdsDefs[path].doc += "\n\n";
479
788
  } else {
480
- cdsDefs[path].doc = "";
789
+ if (cdsDefs[path].doc){
790
+ cdsDefs[path].doc += "";
791
+ }
792
+ else{
793
+ cdsDefs[path].doc = "";
794
+ }
481
795
  }
482
- cdsDefs[path].doc += annotation[1]["@Core.LongDescription"];
796
+ cdsDefs[path].doc += _removeCarriageReturn(annotation[1]["@Core.LongDescription"]);
483
797
  }
484
- if(cdsDefs[annotation[0]]){
485
- if(flag === true){
486
- cdsDefs[annotation[0]].doc += "\n\n ";
798
+ if (cdsDefs[annotation[0]]) {
799
+ if (flag === true) {
800
+ cdsDefs[annotation[0]].doc += "\n\n";
487
801
  } else {
488
- cdsDefs[annotation[0]].doc = "";
802
+ if (cdsDefs[annotation[0]].doc){
803
+ cdsDefs[annotation[0]].doc += "";
804
+ }
805
+ else{
806
+ cdsDefs[annotation[0]].doc = "";
807
+ }
489
808
  }
490
- cdsDefs[annotation[0]].doc += annotation[1]["Core.LongDescription"];
809
+ cdsDefs[annotation[0]].doc += _removeCarriageReturn(annotation[1]["@Core.LongDescription"]);
491
810
  }
492
- }else{
811
+ } else {
493
812
  let path = annotation[0].split('/');
494
- if(cdsDefs[path[0]]["elements"][path[1]]){
495
- if(flag === true){
496
- cdsDefs[path[0]]["elements"][path[1]].doc += "\n\n ";
813
+ if (cdsDefs[path[0]]["elements"][path[1]]) {
814
+ if (flag === true) {
815
+ cdsDefs[path[0]]["elements"][path[1]].doc += "\n\n";
497
816
  } else {
498
- cdsDefs[path[0]]["elements"][path[1]].doc = "";
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 = "";
822
+ }
499
823
  }
500
- cdsDefs[path[0]]["elements"][path[1]].doc += annotation[1]["Core.LongDescription"];
501
- }
502
- }}
503
- })}
504
-
505
-
506
-
507
-
824
+ cdsDefs[path[0]]["elements"][path[1]].doc += _removeCarriageReturn(annotation[1]["@Core.LongDescription"]);
825
+ }
826
+ }
827
+ }
828
+ });
829
+ }
830
+ }
508
831
 
509
832
  function _generateEDMX2JSON(edmx) {
510
833
  return new Promise(function getJson(resolve, reject) {
@@ -513,13 +836,10 @@ function _generateEDMX2JSON(edmx) {
513
836
  // create converter
514
837
  const v4Conv = MetadataConverterFactory.createEdmxV40XmlToV40Json();
515
838
  v4Conv.execute(inputBuffer, (error, json, missingReferencedDocuments) => {
516
- if (error) {
517
- throw error;
518
- }
519
839
  if (missingReferencedDocuments.length > 0) {
520
840
  console.log(missingReferencedDocuments); // eslint-disable-line no-console
521
841
  }
522
-
842
+
523
843
  if (_validateJSON(json)) {
524
844
  resolve(json);
525
845
  }
@@ -530,7 +850,7 @@ function _generateEDMX2JSON(edmx) {
530
850
  });
531
851
  }
532
852
 
533
- function getEdmxv4CSN(edmx, ignorePersistenceSkip, mockServerUc) {
853
+ function getEdmxv4CSN(edmx, mockServerUc) {
534
854
  let csn;
535
855
  let edmjConverted;
536
856
  if (_isJson(edmx)) {
@@ -538,7 +858,7 @@ function getEdmxv4CSN(edmx, ignorePersistenceSkip, mockServerUc) {
538
858
  try {
539
859
  edmjConverted = JSON.parse(edmx);
540
860
  if (_validateJSON(edmjConverted)) {
541
- csn = _generateCSN(edmjConverted, ignorePersistenceSkip, mockServerUc);
861
+ csn = _generateCSN(edmjConverted, mockServerUc);
542
862
  if (csn) {
543
863
  resolve(csn);
544
864
  } else {
@@ -552,7 +872,7 @@ function getEdmxv4CSN(edmx, ignorePersistenceSkip, mockServerUc) {
552
872
  }
553
873
  return _generateEDMX2JSON(edmx).then(function getCsn(edmj) {
554
874
  // now parsing logic
555
- return _generateCSN(edmj, ignorePersistenceSkip, mockServerUc);
875
+ return _generateCSN(edmj, mockServerUc);
556
876
  });
557
877
  }
558
878
 
@@ -1,6 +1,6 @@
1
1
  const os = require('os');
2
2
 
3
- const MAVEN_ARCHETYPE_VERSION = '1.17.0';
3
+ const MAVEN_ARCHETYPE_VERSION = '1.19.0';
4
4
 
5
5
  const constants = {
6
6
  IS_WIN: (os.platform() === 'win32'),