@sap/cds-dk 4.3.3 → 4.5.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 +62 -1
- package/bin/activate.js +1 -2
- package/bin/deploy/index.js +1 -1
- package/bin/deploy/to-sqlite.js +2 -2
- package/bin/extend.js +2 -4
- package/bin/help.js +1 -1
- package/bin/login.js +7 -8
- package/bin/logout.js +1 -2
- package/bin/repl.js +1 -1
- package/bin/watch.js +12 -8
- 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/index.js +17 -38
- package/lib/import/message.js +6 -7
- package/lib/import/v2parser.js +340 -64
- package/lib/import/v4parser.js +346 -59
- package/lib/init/constants.js +1 -1
- package/lib/init/index.js +13 -10
- package/lib/init/template/data/index.js +38 -46
- package/lib/init/template/hana/index.js +2 -2
- package/lib/init/template/lint/files/.eslint/tests/no-entity-moo/fixed/schema.cds +4 -0
- package/lib/init/template/lint/files/.eslint/tests/no-entity-moo/invalid/schema.cds +4 -0
- package/lib/init/template/lint/files/.eslint/tests/no-entity-moo/test.js +10 -0
- package/lib/init/template/lint/files/.eslint/tests/no-entity-moo/valid/schema.cds +6 -0
- 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/init/util/logger.js +1 -1
- package/lib/lint/Linter.js +82 -65
- package/lib/lint/io.js +9 -33
- package/npm-shrinkwrap.json +6327 -11301
- package/package.json +6 -7
- package/lib/init/template/lint/files/.eslint/tests/no-entity-moo.test.js +0 -34
package/lib/import/v4parser.js
CHANGED
|
@@ -5,14 +5,21 @@
|
|
|
5
5
|
|
|
6
6
|
'use strict';
|
|
7
7
|
|
|
8
|
-
let
|
|
8
|
+
let messages = require("./message").getMessages();
|
|
9
9
|
let versionInfo = require('../../package.json').version;
|
|
10
10
|
let namespace;
|
|
11
11
|
let complexTypes = {};
|
|
12
12
|
let enumTypes = {};
|
|
13
|
+
let typeDefinitions = {};
|
|
14
|
+
let unboundedActions = {};
|
|
15
|
+
let boundedActions = {};
|
|
16
|
+
let unboundedFunctions = {};
|
|
17
|
+
let boundedFunctions = {};
|
|
13
18
|
let errors = [];
|
|
14
19
|
let Multimap = require('../import/utils/MultiMap.js');
|
|
15
20
|
let entitySetToEntityTypeMap = new Multimap();
|
|
21
|
+
let actionImportToActionMap = new Multimap();
|
|
22
|
+
let functionImportToFunctionMap = new Multimap();
|
|
16
23
|
let validEdmDatatypes = ['Edm.DateTimeOffset'];
|
|
17
24
|
let jsonEntityContainerName;
|
|
18
25
|
const ignoreObjects = ['$Reference']; // add all the objects that needs to be ignored for parsing.
|
|
@@ -72,7 +79,7 @@ function _isValidJSON(jsonObj) {
|
|
|
72
79
|
return true;
|
|
73
80
|
}
|
|
74
81
|
else {
|
|
75
|
-
throw new Error(
|
|
82
|
+
throw new Error(messages.INVALID_EDMX_METADATA);
|
|
76
83
|
}
|
|
77
84
|
}
|
|
78
85
|
|
|
@@ -80,7 +87,7 @@ function _hasEntityContainer(jsonObj) {
|
|
|
80
87
|
if (jsonObj[namespace][jsonEntityContainerName] && jsonObj[namespace][jsonEntityContainerName] instanceof Object) {
|
|
81
88
|
return true;
|
|
82
89
|
} else {
|
|
83
|
-
throw new Error(
|
|
90
|
+
throw new Error(messages.MISSING_ENTITY_CONTAINER);
|
|
84
91
|
}
|
|
85
92
|
}
|
|
86
93
|
|
|
@@ -96,7 +103,7 @@ function _hasEntitySet(jsonObj) {
|
|
|
96
103
|
});
|
|
97
104
|
|
|
98
105
|
if (entitySetCount == 0) {
|
|
99
|
-
throw new Error(
|
|
106
|
+
throw new Error(messages.MISSING_ENTITY_SETS);
|
|
100
107
|
}
|
|
101
108
|
return true;
|
|
102
109
|
}
|
|
@@ -145,6 +152,12 @@ function _generateComplexTypePropertyCsn(propertyType) {
|
|
|
145
152
|
return property;
|
|
146
153
|
}
|
|
147
154
|
|
|
155
|
+
function _generateTypeDefinitionPropertyCsn(propertyType) {
|
|
156
|
+
let property = {};
|
|
157
|
+
property.type = propertyType.$Type;
|
|
158
|
+
return property;
|
|
159
|
+
}
|
|
160
|
+
|
|
148
161
|
function _parseAssociationProperty(foreignReference, associationNode, mockServerUc) {
|
|
149
162
|
let associationProperty = {};
|
|
150
163
|
let foreignKeys;
|
|
@@ -258,6 +271,10 @@ function _generateCSNForEntityType(entityTypes, ignorePersistenceSkip, mockServe
|
|
|
258
271
|
} else if (element[key][property].$Kind === 'NavigationProperty') {
|
|
259
272
|
entityCsn[key].elements[property] = _parseAssociationProperty(property,
|
|
260
273
|
element[key][property], mockServerUc);
|
|
274
|
+
} else if (typeDefinitions[element[key][property].$Type]){
|
|
275
|
+
// for TypeDefinitions
|
|
276
|
+
propertyType = element[key][property];
|
|
277
|
+
entityCsn[key].elements[property] = _generateTypeDefinitionPropertyCsn(propertyType);
|
|
261
278
|
}
|
|
262
279
|
}
|
|
263
280
|
}
|
|
@@ -309,8 +326,7 @@ function _parseEntityType(schemaDataList, ignorePersistenceSkip, mockServerUc) {
|
|
|
309
326
|
// collect entity types
|
|
310
327
|
let entityTypes = [];
|
|
311
328
|
let schemaData;
|
|
312
|
-
let i = 0;
|
|
313
|
-
for (i = 0; i < schemaDataList.length; i++) {
|
|
329
|
+
for (let i = 0; i < schemaDataList.length; i++) {
|
|
314
330
|
schemaData = schemaDataList[i];
|
|
315
331
|
_generateEntityType(entityTypes, schemaData, mockServerUc);
|
|
316
332
|
}
|
|
@@ -333,16 +349,167 @@ function _generateEnumType(schemaData) {
|
|
|
333
349
|
}
|
|
334
350
|
|
|
335
351
|
function _collectEnumType(schemaDataList) {
|
|
336
|
-
// collect complex types
|
|
337
352
|
let schemaData;
|
|
338
|
-
let i = 0;
|
|
339
|
-
for (i = 0; i < schemaDataList.length; i++) {
|
|
353
|
+
for (let i = 0; i < schemaDataList.length; i++) {
|
|
340
354
|
schemaData = schemaDataList[i];
|
|
341
355
|
enumTypes = _generateEnumType(schemaData);
|
|
342
356
|
}
|
|
343
357
|
return enumTypes;
|
|
344
358
|
}
|
|
345
359
|
|
|
360
|
+
function _generateTypeDefinition(schemaData) {
|
|
361
|
+
let typeDefDict = {};
|
|
362
|
+
let temp;
|
|
363
|
+
Object.keys(schemaData).forEach(curTypeDef => {
|
|
364
|
+
if (schemaData[curTypeDef] instanceof Object) {
|
|
365
|
+
if (schemaData[curTypeDef].$Kind && schemaData[curTypeDef].$Kind === 'TypeDefinition') {
|
|
366
|
+
temp = namespace + '.' + curTypeDef;
|
|
367
|
+
typeDefDict[temp] = schemaData[curTypeDef];
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
return typeDefDict;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function _collectTypeDefinition(schemaDataList) {
|
|
375
|
+
let schemaData;
|
|
376
|
+
for (let i = 0; i < schemaDataList.length; i++) {
|
|
377
|
+
schemaData = schemaDataList[i];
|
|
378
|
+
typeDefinitions = _generateTypeDefinition(schemaData);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function _generateBounded(schemaData, flag) {
|
|
383
|
+
let bFunction = {};
|
|
384
|
+
let boundedFunction = [];
|
|
385
|
+
let temp;
|
|
386
|
+
let kindString;
|
|
387
|
+
if (flag == 1) {
|
|
388
|
+
kindString = 'Function';
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
kindString = 'Action';
|
|
392
|
+
}
|
|
393
|
+
Object.keys(schemaData).forEach(curFunction => {
|
|
394
|
+
if (schemaData[curFunction] instanceof Array && schemaData[curFunction][0].$Kind === kindString && schemaData[curFunction][0].$IsBound === true) {
|
|
395
|
+
boundedFunction = [];
|
|
396
|
+
temp = namespace + '.' + curFunction;
|
|
397
|
+
for (let i = 0; i < schemaData[curFunction].length; i++) {
|
|
398
|
+
boundedFunction.push(schemaData[curFunction][i]);
|
|
399
|
+
bFunction[temp] = boundedFunction;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
return bFunction;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function _collectBounded(schemaDataList , flag) {
|
|
407
|
+
let schemaData;
|
|
408
|
+
for (let i = 0; i < schemaDataList.length; i++) {
|
|
409
|
+
schemaData = schemaDataList[i];
|
|
410
|
+
if (flag == 0) {
|
|
411
|
+
boundedActions = _generateBounded(schemaData, 0);
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
boundedFunctions = _generateBounded(schemaData, 1);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function _parseBounded(csnDefs, flag) {
|
|
420
|
+
let boundedEdmxKind, boundedObj, boundedCsnKind, boundedEntityName, obj, paramType, paramName, paramObj, name, returnType;
|
|
421
|
+
if (flag == 0) {
|
|
422
|
+
boundedEdmxKind = "Action";
|
|
423
|
+
boundedCsnKind = "action";
|
|
424
|
+
boundedObj = boundedActions;
|
|
425
|
+
}
|
|
426
|
+
else {
|
|
427
|
+
boundedEdmxKind = "Function";
|
|
428
|
+
boundedCsnKind = "function";
|
|
429
|
+
boundedObj = boundedFunctions;
|
|
430
|
+
}
|
|
431
|
+
if (Object.keys(boundedObj).length > 0) {
|
|
432
|
+
Object.keys(boundedObj).forEach(b => {
|
|
433
|
+
for (let j = 0; j < boundedObj[b].length; j++) {
|
|
434
|
+
if (boundedObj[b][j].$Kind === boundedEdmxKind) {
|
|
435
|
+
name = b.substring(b.lastIndexOf(".") + 1);
|
|
436
|
+
obj = boundedObj[b];
|
|
437
|
+
boundedEntityName = obj[j].$Parameter[0].$Type;
|
|
438
|
+
if (csnDefs[boundedEntityName] === undefined) {
|
|
439
|
+
boundedEntityName = namespace + "." + entitySetToEntityTypeMap.get(boundedEntityName)[0];
|
|
440
|
+
}
|
|
441
|
+
if (csnDefs[boundedEntityName]) {
|
|
442
|
+
if (csnDefs[boundedEntityName].actions === undefined)
|
|
443
|
+
csnDefs[boundedEntityName].actions = {};
|
|
444
|
+
csnDefs[boundedEntityName].actions[name] = {};
|
|
445
|
+
csnDefs[boundedEntityName].actions[name].kind = boundedCsnKind;
|
|
446
|
+
// add params
|
|
447
|
+
if (obj[j].$Parameter && obj[j].$Parameter.length >= 2) {
|
|
448
|
+
/**
|
|
449
|
+
* 1. Considering length >= 2 because we need to consider from the 2nd
|
|
450
|
+
* parameter onwards. 1st parameter only tells which entity is this
|
|
451
|
+
* action/function bounded to and that parameter is no where used
|
|
452
|
+
* to retrieve any data during service runtime. So skipping it and
|
|
453
|
+
* the details of 1st parameter will not be preserved in the csn.
|
|
454
|
+
* 2. The 1st parameter will be reflected back as parameter name "in"
|
|
455
|
+
* during csn to edmx conversion by the compiler.
|
|
456
|
+
* */
|
|
457
|
+
csnDefs[boundedEntityName].actions[name].params = {};
|
|
458
|
+
for (let i = 1; i < obj[j].$Parameter.length; i++) {
|
|
459
|
+
paramObj = obj[j].$Parameter[i];
|
|
460
|
+
paramName = obj[j].$Parameter[i].$Name;
|
|
461
|
+
// check if the parameter type is pre-defined, undefined or custom defined
|
|
462
|
+
if (edmxncdsdatatype[paramObj.$Type])
|
|
463
|
+
paramType = generatePropertyCsn(paramObj, false);
|
|
464
|
+
else if (paramObj.$Type === undefined)
|
|
465
|
+
paramType = { "type": "cds.LargeString" }; // intentionally used LargeString
|
|
466
|
+
else {
|
|
467
|
+
if (entitySetToEntityTypeMap.get(obj[j].$Parameter[i].$Type)) {
|
|
468
|
+
let type = namespace + "." + entitySetToEntityTypeMap.get(obj[j].$Parameter[i].$Type)[0];
|
|
469
|
+
paramType = { "type": type };
|
|
470
|
+
}
|
|
471
|
+
else {
|
|
472
|
+
paramType = { "type": obj[j].$Parameter[i].$Type };
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
// check if parameter type is a collection
|
|
476
|
+
if (paramObj.$Collection) {
|
|
477
|
+
csnDefs[boundedEntityName].actions[name].params[paramName] = {};
|
|
478
|
+
csnDefs[boundedEntityName].actions[name].params[paramName].items = paramType;
|
|
479
|
+
} else
|
|
480
|
+
csnDefs[boundedEntityName].actions[name].params[paramName] = paramType;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
// add returns
|
|
484
|
+
if (obj[j].$ReturnType) {
|
|
485
|
+
csnDefs[boundedEntityName].actions[name].returns = {};
|
|
486
|
+
// check if the return type is pre-defined, undefined or custom defined
|
|
487
|
+
if (edmxncdsdatatype[obj[j].$ReturnType.$Type])
|
|
488
|
+
returnType = generatePropertyCsn(obj[j].$ReturnType, false);
|
|
489
|
+
else if (obj[j].$ReturnType.$Type === undefined)
|
|
490
|
+
returnType = { "type": "cds.LargeString" }; // intentionally used LargeString
|
|
491
|
+
else {
|
|
492
|
+
if (entitySetToEntityTypeMap.get(obj[j].$ReturnType.$Type) && entitySetToEntityTypeMap.get(obj[j].$ReturnType.$Type)[0]) {
|
|
493
|
+
let type = namespace + "." + entitySetToEntityTypeMap.get(obj[j].$ReturnType.$Type)[0];
|
|
494
|
+
returnType = { "type": type };
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
returnType = { "type": obj[j].$ReturnType.$Type };
|
|
498
|
+
}
|
|
499
|
+
}
|
|
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
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
346
513
|
function _generateComplexType(schemaData) {
|
|
347
514
|
let complexTypeDict = {};
|
|
348
515
|
let temp;
|
|
@@ -360,8 +527,7 @@ function _generateComplexType(schemaData) {
|
|
|
360
527
|
function _collectComplexType(schemaDataList) {
|
|
361
528
|
// collect complex types
|
|
362
529
|
let schemaData;
|
|
363
|
-
let i = 0;
|
|
364
|
-
for (i = 0; i < schemaDataList.length; i++) {
|
|
530
|
+
for (let i = 0; i < schemaDataList.length; i++) {
|
|
365
531
|
schemaData = schemaDataList[i];
|
|
366
532
|
complexTypes = _generateComplexType(schemaData);
|
|
367
533
|
}
|
|
@@ -399,10 +565,110 @@ function _generateCSNForComplexType(schemaData) {
|
|
|
399
565
|
return complexCsn;
|
|
400
566
|
}
|
|
401
567
|
|
|
568
|
+
function _parseTypeDefinition() {
|
|
569
|
+
let typeDef = {};
|
|
570
|
+
let propertyType;
|
|
571
|
+
Object.keys(typeDefinitions).forEach(element => {
|
|
572
|
+
typeDef[element] = {};
|
|
573
|
+
typeDef[element].kind = 'type';
|
|
574
|
+
if (!typeDefinitions[element].$Type || edmxncdsdatatype[typeDefinitions[element].$Type]) {
|
|
575
|
+
propertyType = typeDefinitions[element];
|
|
576
|
+
typeDef[element] = Object.assign(typeDef[element], generatePropertyCsn(propertyType, false));
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
return typeDef;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
function _parseUnbounded(schemaData, flag) {
|
|
583
|
+
let unboundedObj = {}, unbounded, unboundedCsnKind;
|
|
584
|
+
let importToMap = new Multimap();
|
|
585
|
+
if (flag == 0) {
|
|
586
|
+
unbounded = unboundedActions;
|
|
587
|
+
importToMap = actionImportToActionMap;
|
|
588
|
+
unboundedCsnKind = "action";
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
unbounded = unboundedFunctions;
|
|
592
|
+
importToMap = functionImportToFunctionMap;
|
|
593
|
+
unboundedCsnKind = "function";
|
|
594
|
+
}
|
|
595
|
+
if (Object.keys(unbounded).length > 0) {
|
|
596
|
+
Object.keys(unbounded).forEach(ub => {
|
|
597
|
+
let obj = {};
|
|
598
|
+
let objType = {}, objData = {}, temp;
|
|
599
|
+
if (importToMap && importToMap.get(ub)) {
|
|
600
|
+
temp = importToMap.get(ub)[0];
|
|
601
|
+
objType = namespace + "." + temp;
|
|
602
|
+
objData = schemaData[0][temp][0];
|
|
603
|
+
obj[objType] = {};
|
|
604
|
+
obj[objType].kind = unboundedCsnKind;
|
|
605
|
+
// add params
|
|
606
|
+
if (objData.$Parameter && objData.$Parameter.length > 0) {
|
|
607
|
+
obj[objType].params = {};
|
|
608
|
+
let type;
|
|
609
|
+
for (let i = 0; i < objData.$Parameter.length; i++) {
|
|
610
|
+
obj[objType].params[objData.$Parameter[i].$Name] = {};
|
|
611
|
+
// check if the parameter type is pre-defined, undefined or custom defined
|
|
612
|
+
if (edmxncdsdatatype[objData.$Parameter[i].$Type]) {
|
|
613
|
+
type = (generatePropertyCsn(objData.$Parameter[i], false)).type;
|
|
614
|
+
}
|
|
615
|
+
else if (objData.$Parameter[i].$Type === undefined) {
|
|
616
|
+
type = "cds.LargeString"; // intentionally used LargeString
|
|
617
|
+
}
|
|
618
|
+
else {
|
|
619
|
+
if (entitySetToEntityTypeMap.get(objData.$Parameter[i].$Type))
|
|
620
|
+
type = namespace + "." + entitySetToEntityTypeMap.get(objData.$Parameter[i].$Type)[0];
|
|
621
|
+
else
|
|
622
|
+
type = objData.$Parameter[i].$Type;
|
|
623
|
+
}
|
|
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
|
+
}
|
|
630
|
+
}
|
|
631
|
+
// add returns
|
|
632
|
+
if (objData.$ReturnType && Object.keys(objData.$ReturnType).length > 0 && obj) {
|
|
633
|
+
obj[objType].returns = {};
|
|
634
|
+
let returnValue;
|
|
635
|
+
// check if the return type is pre-defined, undefined or custom defined
|
|
636
|
+
if (edmxncdsdatatype[objData.$ReturnType.$Type]) {
|
|
637
|
+
returnValue = generatePropertyCsn(objData.$ReturnType, false);
|
|
638
|
+
}
|
|
639
|
+
else if (objData.$ReturnType.$Type === undefined) {
|
|
640
|
+
returnValue = { "type": "cds.LargeString" }; // intentionally used LargeString
|
|
641
|
+
}
|
|
642
|
+
else {
|
|
643
|
+
if (entitySetToEntityTypeMap.get(objData.$ReturnType.$Type) && entitySetToEntityTypeMap.get(objData.$ReturnType.$Type)[0]) {
|
|
644
|
+
let type = namespace + "." + entitySetToEntityTypeMap.get(objData.$ReturnType.$Type)[0];
|
|
645
|
+
returnValue = { "type": type };
|
|
646
|
+
}
|
|
647
|
+
else
|
|
648
|
+
returnValue = { "type": objData.$ReturnType.$Type };
|
|
649
|
+
}
|
|
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
|
+
}
|
|
657
|
+
}
|
|
658
|
+
unboundedObj = Object.assign(unboundedObj, obj);
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
return unboundedObj;
|
|
662
|
+
}
|
|
663
|
+
|
|
402
664
|
function _generateCSN(edmxAsJson, ignorePersistenceSkip, mockServerUc) {
|
|
403
665
|
let schemaCounter = 0;
|
|
404
666
|
let csn = {};
|
|
405
667
|
let schemaData = [];
|
|
668
|
+
unboundedActions = {};
|
|
669
|
+
boundedActions = {};
|
|
670
|
+
unboundedFunctions = {};
|
|
671
|
+
boundedFunctions = {};
|
|
406
672
|
csn.meta = {};
|
|
407
673
|
csn.meta.creator = 'cds-dk ' + versionInfo;
|
|
408
674
|
csn.$version = '2.0';
|
|
@@ -421,6 +687,14 @@ function _generateCSN(edmxAsJson, ignorePersistenceSkip, mockServerUc) {
|
|
|
421
687
|
if (ignoreObjects.indexOf(data) === -1 && entityContainer[data] instanceof Object &&
|
|
422
688
|
entityContainer[data].$Type && entityContainer[data].$Collection) {
|
|
423
689
|
entitySetToEntityTypeMap.set(entityContainer[data].$Type, data);
|
|
690
|
+
} else if (ignoreObjects.indexOf(data) === -1 && entityContainer[data] instanceof Object &&
|
|
691
|
+
entityContainer[data].$Action) {
|
|
692
|
+
actionImportToActionMap.set(entityContainer[data].$Action, data);
|
|
693
|
+
unboundedActions[entityContainer[data].$Action] = entitySetData[data];
|
|
694
|
+
} else if (ignoreObjects.indexOf(data) === -1 && entityContainer[data] instanceof Object &&
|
|
695
|
+
entityContainer[data].$Function) {
|
|
696
|
+
functionImportToFunctionMap.set(entityContainer[data].$Function, data);
|
|
697
|
+
unboundedFunctions[entityContainer[data].$Function] = entitySetData[data];
|
|
424
698
|
}
|
|
425
699
|
});
|
|
426
700
|
}
|
|
@@ -433,78 +707,94 @@ function _generateCSN(edmxAsJson, ignorePersistenceSkip, mockServerUc) {
|
|
|
433
707
|
|
|
434
708
|
// Multiple schema found and currently we don't support
|
|
435
709
|
if (schemaCounter > 1) {
|
|
436
|
-
let errorMsg =
|
|
710
|
+
let errorMsg = messages().MULTIPLE_SCHEMA_FOUND;
|
|
437
711
|
errors.push(errorMsg);
|
|
438
712
|
// throw errorMsg;
|
|
439
713
|
}
|
|
440
|
-
|
|
714
|
+
|
|
441
715
|
csn.definitions[namespace] = {};
|
|
442
716
|
csn.definitions[namespace].kind = 'service';
|
|
717
|
+
|
|
443
718
|
_collectEnumType(schemaData);
|
|
719
|
+
_collectTypeDefinition(schemaData);
|
|
720
|
+
_collectBounded(schemaData,0);
|
|
721
|
+
_collectBounded(schemaData,1);
|
|
722
|
+
|
|
723
|
+
// Step 1: get all complex types.
|
|
444
724
|
csn.definitions = Object.assign(_generateCSNForComplexType(schemaData), csn.definitions);
|
|
445
|
-
// Step 2:
|
|
725
|
+
// Step 2: get all type definition
|
|
726
|
+
csn.definitions = Object.assign(_parseTypeDefinition(), csn.definitions);
|
|
727
|
+
// Step 3: get all unbounded action & function
|
|
728
|
+
csn.definitions = Object.assign(_parseUnbounded(schemaData, 0), csn.definitions);
|
|
729
|
+
csn.definitions = Object.assign(_parseUnbounded(schemaData , 1), csn.definitions);
|
|
730
|
+
// Step 4: get all entity type
|
|
446
731
|
csn.definitions = Object.assign(_parseEntityType(schemaData, ignorePersistenceSkip, mockServerUc), csn.definitions);
|
|
447
|
-
|
|
732
|
+
// Step 5: get all bounded action & function
|
|
733
|
+
_parseBounded(csn.definitions, 0 );
|
|
734
|
+
_parseBounded(csn.definitions, 1 );
|
|
735
|
+
// Step 6: get all annotations
|
|
736
|
+
_generateDocumentation(schemaData, csn.definitions);
|
|
737
|
+
|
|
448
738
|
return JSON.stringify(csn, null, 4);
|
|
449
739
|
}
|
|
450
740
|
|
|
451
|
-
function _generateDocumentation(schemaData,cdsDefs){
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
741
|
+
function _generateDocumentation(schemaData, cdsDefs) {
|
|
742
|
+
if (schemaData[0].$Annotations) {
|
|
743
|
+
Object.entries(schemaData[0].$Annotations).map(annotation => {
|
|
744
|
+
let flag;
|
|
745
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
746
|
+
if (annotation[1].hasOwnProperty('@Core.Description')) {
|
|
747
|
+
flag = true;
|
|
748
|
+
if (annotation[0].indexOf('/') === -1) {
|
|
749
|
+
if (annotation[0].endsWith(".EntityContainer")) {
|
|
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
|
+
}
|
|
465
761
|
}
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
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")){
|
|
762
|
+
}
|
|
763
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
764
|
+
if (annotation[1].hasOwnProperty('@Core.LongDescription')) {
|
|
765
|
+
if (annotation[0].indexOf('/') === -1) {
|
|
766
|
+
if (annotation[0].endsWith(".EntityContainer")) {
|
|
476
767
|
let path = annotation[0].split(".")[0];
|
|
477
|
-
if(flag === true){
|
|
478
|
-
cdsDefs[path].doc += "\n\n
|
|
768
|
+
if (flag === true) {
|
|
769
|
+
cdsDefs[path].doc += "\n\n";
|
|
479
770
|
} else {
|
|
480
771
|
cdsDefs[path].doc = "";
|
|
481
772
|
}
|
|
482
773
|
cdsDefs[path].doc += annotation[1]["@Core.LongDescription"];
|
|
483
774
|
}
|
|
484
|
-
if(cdsDefs[annotation[0]]){
|
|
485
|
-
if(flag === true){
|
|
486
|
-
cdsDefs[annotation[0]].doc += "\n\n
|
|
775
|
+
if (cdsDefs[annotation[0]]) {
|
|
776
|
+
if (flag === true) {
|
|
777
|
+
cdsDefs[annotation[0]].doc += "\n\n";
|
|
487
778
|
} else {
|
|
488
779
|
cdsDefs[annotation[0]].doc = "";
|
|
489
780
|
}
|
|
490
781
|
cdsDefs[annotation[0]].doc += annotation[1]["Core.LongDescription"];
|
|
491
782
|
}
|
|
492
|
-
}else{
|
|
783
|
+
} else {
|
|
493
784
|
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
|
|
785
|
+
if (cdsDefs[path[0]]["elements"][path[1]]) {
|
|
786
|
+
if (flag === true) {
|
|
787
|
+
cdsDefs[path[0]]["elements"][path[1]].doc += "\n\n";
|
|
497
788
|
} else {
|
|
498
789
|
cdsDefs[path[0]]["elements"][path[1]].doc = "";
|
|
499
790
|
}
|
|
500
791
|
cdsDefs[path[0]]["elements"][path[1]].doc += annotation[1]["Core.LongDescription"];
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
}
|
|
508
798
|
|
|
509
799
|
function _generateEDMX2JSON(edmx) {
|
|
510
800
|
return new Promise(function getJson(resolve, reject) {
|
|
@@ -513,13 +803,10 @@ function _generateEDMX2JSON(edmx) {
|
|
|
513
803
|
// create converter
|
|
514
804
|
const v4Conv = MetadataConverterFactory.createEdmxV40XmlToV40Json();
|
|
515
805
|
v4Conv.execute(inputBuffer, (error, json, missingReferencedDocuments) => {
|
|
516
|
-
if (error) {
|
|
517
|
-
throw error;
|
|
518
|
-
}
|
|
519
806
|
if (missingReferencedDocuments.length > 0) {
|
|
520
807
|
console.log(missingReferencedDocuments); // eslint-disable-line no-console
|
|
521
808
|
}
|
|
522
|
-
|
|
809
|
+
|
|
523
810
|
if (_validateJSON(json)) {
|
|
524
811
|
resolve(json);
|
|
525
812
|
}
|
package/lib/init/constants.js
CHANGED
package/lib/init/index.js
CHANGED
|
@@ -6,7 +6,7 @@ const term = require('../util/term');
|
|
|
6
6
|
const Spinner = require('./util/spinner');
|
|
7
7
|
|
|
8
8
|
const { OPTIONS_PRIORITY, COMMAND_ADD, COMMAND_INIT,
|
|
9
|
-
OPTION_HANA, OPTION_JAVA, OPTION_MTA, OPTION_MTX, OPTION_NODEJS,
|
|
9
|
+
OPTION_HANA, OPTION_JAVA, OPTION_MTA, OPTION_MTX, OPTION_NODEJS,
|
|
10
10
|
OPTION_PIPELINE, OPTION_SAMPLES, OPTION_CF_MANIFEST, PROJECT_FILES, REGEX_PROJECT_NAME } = require('./constants');
|
|
11
11
|
|
|
12
12
|
module.exports = class CDSGenerator {
|
|
@@ -23,7 +23,7 @@ module.exports = class CDSGenerator {
|
|
|
23
23
|
validate: async (value) => {
|
|
24
24
|
try {
|
|
25
25
|
await this._validateProjectName(value);
|
|
26
|
-
await this._validateProjectFolder(path.join(
|
|
26
|
+
await this._validateProjectFolder(path.join(this.cwd, value), this.cwd);
|
|
27
27
|
|
|
28
28
|
return true;
|
|
29
29
|
} catch (err) {
|
|
@@ -279,7 +279,7 @@ module.exports = class CDSGenerator {
|
|
|
279
279
|
let tokens = [];
|
|
280
280
|
|
|
281
281
|
if (typeof this.options.add === 'string') {
|
|
282
|
-
tokens = this.options.add.split(
|
|
282
|
+
tokens = this.options.add.split(/[,\s+]/g);
|
|
283
283
|
|
|
284
284
|
} else if (Array.isArray(this.options.add)) {
|
|
285
285
|
tokens = this.options.add
|
|
@@ -310,15 +310,18 @@ module.exports = class CDSGenerator {
|
|
|
310
310
|
this.options.add.add(OPTION_NODEJS);
|
|
311
311
|
}
|
|
312
312
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
313
|
+
this._checkAdditionalOptions();
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
_checkAdditionalOptions() {
|
|
317
|
+
for (const [key] of Object.entries(this.options)) {
|
|
318
|
+
const keySplit = key.split(/:/);
|
|
319
|
+
if (keySplit.length === 2) {
|
|
320
|
+
if (!this.options.add.has(keySplit[0])) {
|
|
321
|
+
this.logger.warn(`ignoring option ${key} since ${keySplit[0]} is not part of specified feature list: ${Array.from(this.options.add).join(', ')}`);
|
|
322
|
+
}
|
|
319
323
|
}
|
|
320
324
|
}
|
|
321
|
-
|
|
322
325
|
}
|
|
323
326
|
|
|
324
327
|
async _validateOptions() {
|