@sap/cds-dk 7.0.3 → 7.1.1

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 (47) hide show
  1. package/bin/bind.js +5 -6
  2. package/bin/build.js +2 -7
  3. package/bin/cds.js +2 -5
  4. package/bin/subscribe.js +4 -4
  5. package/bin/unsubscribe.js +4 -4
  6. package/bin/upgrade.js +4 -4
  7. package/lib/bind/cfKeyProvider.js +9 -10
  8. package/lib/bind/index.js +1 -3
  9. package/lib/build/buildTaskEngine.js +10 -22
  10. package/lib/build/buildTaskFactory.js +18 -27
  11. package/lib/build/buildTaskHandler.js +4 -7
  12. package/lib/build/index.js +12 -3
  13. package/lib/build/provider/buildTaskProviderInternal.js +23 -15
  14. package/lib/build/provider/fiori/index.js +4 -3
  15. package/lib/build/provider/java/index.js +2 -2
  16. package/lib/build/provider/mtx/index.js +8 -2
  17. package/lib/build/util.js +13 -0
  18. package/lib/client/activate.js +7 -7
  19. package/lib/client/auth_manager.js +5 -5
  20. package/lib/client/base_command.js +5 -5
  21. package/lib/client/extend.js +2 -2
  22. package/lib/client/helper/logging.js +7 -2
  23. package/lib/client/params.js +2 -3
  24. package/lib/client/pull.js +3 -3
  25. package/lib/client/push.js +3 -3
  26. package/lib/client/settings_manager.js +7 -8
  27. package/lib/client/tenant_action.js +3 -3
  28. package/lib/deploy/to-hana/hana.js +1 -2
  29. package/lib/import/common.js +3 -0
  30. package/lib/import/message.js +8 -2
  31. package/lib/import/odata/metadataconverter/MetadataConverter.js +13 -9
  32. package/lib/import/odata/v4parser.js +111 -107
  33. package/lib/init/constants.js +1 -1
  34. package/lib/init/index.js +24 -11
  35. package/lib/init/template/cf-manifest/files/manifest.yml.hbs +1 -1
  36. package/lib/init/template/data/index.js +2 -3
  37. package/lib/init/template/lint/index.js +5 -6
  38. package/lib/init/template/nodejs/index.js +2 -3
  39. package/lib/init/template/pipeline/index.js +1 -2
  40. package/lib/init/util/indent.js +1 -1
  41. package/lib/init/util/merge.js +3 -3
  42. package/lib/init/util/mvn.js +17 -22
  43. package/lib/util/cfUtil.js +1 -2
  44. package/npm-shrinkwrap.json +51 -53
  45. package/package.json +3 -2
  46. package/lib/client/helper/errors.js +0 -26
  47. package/lib/util/version.js +0 -27
@@ -82,7 +82,7 @@ const known_vocabularies = {
82
82
  'com.sap.vocabularies.UI.v1': 'UI',
83
83
  };
84
84
 
85
- function _initialize(parserContext) {
85
+ function _initialize(parserContext, mockServerUc) {
86
86
  parserContext.unboundedActions = {};
87
87
  parserContext.unboundedFunctions = {};
88
88
  parserContext.entityTypes = [];
@@ -103,8 +103,8 @@ function _initialize(parserContext) {
103
103
  parserContext.entityToBoundedActions = {};
104
104
  parserContext.entityToBoundedFunctions = {};
105
105
  parserContext.entityContainerAnnotations = {};
106
+ parserContext.mockServerUc = mockServerUc;
106
107
  }
107
-
108
108
  function _isJson(edmx) {
109
109
  let isJson = false;
110
110
  try {
@@ -124,8 +124,8 @@ function _extractSchemaNameAndElementName(name) {
124
124
  }
125
125
 
126
126
  /**
127
- * @param {String} fqName
128
- * @param {String} schemaName
127
+ * @param {String} fqName
128
+ * @param {String} schemaName
129
129
  * @param {Object} parserContext
130
130
  * @returns index of schemaName in the schemaDataList
131
131
  */
@@ -155,31 +155,16 @@ function _resolveAliasedElementName(fqName, parserContext) {
155
155
  return schemaName + '.' + elementName;
156
156
  }
157
157
 
158
- function _isValidJSON(jsonObj, parserContext, context) {
159
- if (jsonObj.$Version && _hasEntityContainer(jsonObj, parserContext, context) && jsonObj[parserContext.primarySchema]) {
160
- return true;
158
+ function _collectPrimarySchemaContext(jsonObj, parserContext, importerContext) {
159
+ let jsonObjEntityContainer = jsonObj.$EntityContainer;
160
+ if (jsonObjEntityContainer) {
161
+ // scenario: Schema Namespace="A.B.C.D" & jsonObjEntityContainer is "A.B.C.D.EntityContainerName"
162
+ [parserContext.primarySchema, parserContext.entityContainerName] = _extractSchemaNameAndElementName(jsonObjEntityContainer);
163
+ // required for `--keep-namespace` scenario
164
+ importerContext.schemaNamespace = parserContext.primarySchema;
161
165
  }
162
166
  else {
163
- throw new Error(messages.INVALID_EDMX_METADATA);
164
- }
165
- }
166
-
167
- function _hasEntityContainer(jsonObj, parserContext, context) {
168
- let jsonObjEntityContainer = jsonObj.$EntityContainer;
169
- try {
170
- if (jsonObjEntityContainer) {
171
- // scenario: Schema Namespace="A.B.C.D" & jsonObjEntityContainer is "A.B.C.D.EntityContainerName"
172
- [parserContext.primarySchema, parserContext.entityContainerName] = _extractSchemaNameAndElementName(jsonObjEntityContainer);
173
- // required for `--keep-namespace` scenario
174
- context.schemaNamespace = parserContext.primarySchema;
175
- }
176
- if (jsonObj[parserContext.primarySchema][parserContext.entityContainerName] &&
177
- jsonObj[parserContext.primarySchema][parserContext.entityContainerName] instanceof Object
178
- ) {
179
- return true;
180
- }
181
- } catch (err) {
182
- throw new Error(messages.MISSING_ENTITY_CONTAINER);
167
+ parserContext.mockServerUc = false;
183
168
  }
184
169
  }
185
170
 
@@ -205,36 +190,44 @@ function _updateElementObjectForDefaultValue(dataTypeObj, defaultvalue) {
205
190
  // for collection, default value isin't expected
206
191
  if (dataTypeObj.items === undefined) {
207
192
  dataTypeObj.default = {};
208
- dataTypeObj.default.val = (defaultvalue) ? defaultvalue : null;
193
+ // defaultvalue could be of type string (eg., '0') or number (eg., 0 or -1.5)
194
+ dataTypeObj.default.val = (defaultvalue !== undefined) ? defaultvalue : null;
209
195
  }
210
196
  else {
211
- console.log(warn("Collection type cannot have a Default value."));
197
+ console.log(warn(messages.NO_DEFAULT_FOR_COLLECTIONS));
212
198
  }
213
199
  }
214
200
 
215
201
  function _updateDataTypeObjectForMaxLength(dataTypeObj, propertyDataType, maxLength) {
216
- const mappedValue = edmToCdsTypeMappingWithMaxLength[propertyDataType];
202
+ const mappedValue = edmToCdsTypeMappingWithMaxLength[propertyDataType];
217
203
 
218
204
  if (mappedValue) {
219
205
  dataTypeObj.type = mappedValue
220
206
  dataTypeObj.length = maxLength;
221
207
  }
222
- if (propertyDataType === 'Edm.Binary' && maxLength >= 5000) {
223
- console.log(warn("MaxLength for type Edm.Binary should not exceed 5000"));
208
+ if (propertyDataType === 'Edm.Binary' && maxLength > 5000) {
209
+ console.log(warn(messages.BINARY_MAXLENGTH));
224
210
  }
225
211
  }
226
212
 
227
213
  function _updateDataTypeObjectForPrecision(dataTypeObj, propertyDataType, precision, scale) {
228
214
  const mappedValue = edmToCdsTypeMappingWithPrecision[propertyDataType];
215
+ const numberedScale = Number(scale);
229
216
 
230
217
  if (mappedValue) {
231
218
  dataTypeObj.type = mappedValue;
232
- if (Number(precision) > 0) {
219
+ if (precision >= 0) {
233
220
  dataTypeObj.precision = precision;
234
221
  }
235
- if (Number(scale) > 0 || scale === 'floating' || scale === 'variable') {
222
+ if (numberedScale >= 0) {
236
223
  dataTypeObj.scale = scale;
237
224
  }
225
+ if (numberedScale > precision) {
226
+ console.log(warn(messages.SCALE_GT_PRECISION));
227
+ }
228
+ if (precision >= 0 && (scale === 'floating' || scale === 'variable')) {
229
+ console.log(warn(messages.FIXED_PRECISION_VARIABLE_SCALE));
230
+ }
238
231
  }
239
232
  }
240
233
 
@@ -301,7 +294,7 @@ function _resolveCoreTerm(annotationTerm, annotationTermObject, csnDefsTargetObj
301
294
  if (annotationTerm === "@Core.Description" || annotationTerm === "@Core.LongDescription") {
302
295
  // we don't capture `null` value for doc
303
296
  if (annotationTermObject === null) return;
304
-
297
+
305
298
  annotationTermObject = _replaceSpecialCharacters(annotationTermObject);
306
299
 
307
300
  if (csnDefsTargetObject.doc) {
@@ -372,7 +365,7 @@ function _parseCapabilitiesTerm(annotationTerm, annotationTermObject, csnDefsTar
372
365
  * For entries like:
373
366
  * <Annotation Term="Capabilities.FilterFunctions"> <Collection> <String>eq</String> <String>ne</String> </Collection> </Annotation>
374
367
  * <Annotation Term="Capabilities.DeleteRestrictions.Deletable" Bool="true"/>
375
- *
368
+ *
376
369
  * simply preserve the value as it is
377
370
  */
378
371
  if (annotationTermObject instanceof Array || !(annotationTermObject instanceof Object)) {
@@ -433,8 +426,8 @@ function _parseAnnotationTerms(annotationTerm, annotationTermObject, csnDefsTarg
433
426
  function _resolveAnotationTerm(schemaDataAnnotation, parserContext) {
434
427
  // Case 1: We have the Namespace and Alias for the vocabulary
435
428
  for (const [alias, namespace] of Object.entries(parserContext.vocabAliasToNamespace)) {
436
- if (schemaDataAnnotation.includes(alias)) {
437
- schemaDataAnnotation = schemaDataAnnotation.split(alias).join(known_vocabularies[namespace]);
429
+ if (schemaDataAnnotation.includes('@' + alias)) {
430
+ schemaDataAnnotation = schemaDataAnnotation.split('@' + alias).join('@' + known_vocabularies[namespace]);
438
431
  }
439
432
  }
440
433
  /**
@@ -452,10 +445,10 @@ function _resolveAnotationTerm(schemaDataAnnotation, parserContext) {
452
445
 
453
446
  /**
454
447
  * Capture all the annotation cases withtin an Element
455
- *
448
+ *
456
449
  * UnKnown term: <Annotation Term="Org.OData.ASDF.V1.qwe"/>
457
450
  * Known term: <Annotation Term="Org.OData.Measures.V1.Unit" String="Centimeters"/>
458
- *
451
+ *
459
452
  * if "--include-namespaces *" then we also capture for ABS and QWE
460
453
  * <TypeDefinition Name="TD_2" UnderlyingType="Edm.Int32" ABS:asdf="testing" QWE:qwe="testing"/>
461
454
  */
@@ -484,7 +477,7 @@ function _generatePrimitiveDataTypeCsn(propertyObject, isPrimaryKey, parserConte
484
477
  if (isPrimaryKey) {
485
478
  dataTypeObj.key = true;
486
479
  if (nullable) {
487
- console.log(warn("Key element cannot be Nullable."));
480
+ console.log(warn(messages.NULLABLE_KEY));
488
481
  }
489
482
  }
490
483
  _captureAnnotationWithinElement(propertyObject, dataTypeObj, parserContext);
@@ -494,7 +487,11 @@ function _generatePrimitiveDataTypeCsn(propertyObject, isPrimaryKey, parserConte
494
487
  if (maxLength) {
495
488
  _updateDataTypeObjectForMaxLength(dataTypeObj, propertyDataType, maxLength);
496
489
  }
497
- if (precision || scale) {
490
+ /**
491
+ * Precision: non-negative integers
492
+ * Scale: non-negative integers, variable, floating
493
+ */
494
+ if (precision >= 0 || scale !== undefined) {
498
495
  _updateDataTypeObjectForPrecision(dataTypeObj, propertyDataType, precision, scale);
499
496
  }
500
497
  if (edmToCdsTypeSpecialHandling[propertyDataType]) {
@@ -518,7 +515,8 @@ function _generatePrimitiveDataTypeCsn(propertyObject, isPrimaryKey, parserConte
518
515
  if (isCollection) {
519
516
  _updateElementObjectForCollection(dataTypeObj, isPrimaryKey, propertyDataType);
520
517
  }
521
- if (defaultvalue) {
518
+ // defaultvalue could be of type string (eg., '0') or number (eg., 0 or -1.5)
519
+ if (defaultvalue !== undefined) {
522
520
  _updateElementObjectForDefaultValue(dataTypeObj, defaultvalue);
523
521
  }
524
522
 
@@ -536,7 +534,7 @@ function _getEntityTypeMappedName(entityType, parserContext) {
536
534
  }
537
535
  }
538
536
 
539
- function _generateStructuredDataTypeCsn(dataType, propertyObject, isPrimaryKey, dataTypeKind, elementKind, mockServerUc, parserContext) {
537
+ function _generateStructuredDataTypeCsn(dataType, propertyObject, isPrimaryKey, dataTypeKind, elementKind, parserContext) {
540
538
  const dataTypeObj = {};
541
539
  const isCollection = propertyObject.$Collection;
542
540
  const nullable = propertyObject.$Nullable;
@@ -553,12 +551,12 @@ function _generateStructuredDataTypeCsn(dataType, propertyObject, isPrimaryKey,
553
551
  if (isPrimaryKey) {
554
552
  dataTypeObj.key = true;
555
553
  if (nullable) {
556
- console.log(warn("Key element cannot be Nullable."));
554
+ console.log(warn(messages.NULLABLE_KEY));
557
555
  }
558
556
  }
559
557
 
560
558
  // if dataTypeKind is EntityType, also check for mapped entity name
561
- if (mockServerUc && dataTypeKind === 'EntityType') {
559
+ if (parserContext.mockServerUc && dataTypeKind === 'EntityType') {
562
560
  // propertyDataType is resolved fully qualified name
563
561
  if (parserContext.entityToEntitySetMap?.get(propertyDataType)) {
564
562
  propertyDataType = _getEntityTypeMappedName(propertyDataType, parserContext);
@@ -578,12 +576,13 @@ function _generateStructuredDataTypeCsn(dataType, propertyObject, isPrimaryKey,
578
576
  }
579
577
  /**
580
578
  * only Primitive type and EnumType can have DefaultValue facet as per documentation
581
- * but compiler accepts it for TypeDefintion and ComplexType as well,
579
+ * but compiler accepts it for TypeDefintion and ComplexType as well,
582
580
  * do we also need to handle it for TypeDefintion and ComplexType?
583
- *
584
- * For parameters, default value is added via OptionalParamter Annotation
581
+ *
582
+ * For parameters, defaultvalue is added via OptionalParamter Annotation
583
+ * defaultvalue could be of type string (eg., '0') or number (eg., 0 or -1.5)
585
584
  */
586
- if (defaultvalue && dataTypeKind === 'EnumType' && elementKind === 'property') {
585
+ if (defaultvalue !== undefined && dataTypeKind === 'EnumType' && elementKind === 'property') {
587
586
  _updateElementObjectForDefaultValue(dataTypeObj, defaultvalue);
588
587
  }
589
588
  else {
@@ -594,7 +593,7 @@ function _generateStructuredDataTypeCsn(dataType, propertyObject, isPrimaryKey,
594
593
  return dataTypeObj;
595
594
  }
596
595
 
597
- function _parseAssociationProperty(foreignReference, associationNode, mockServerUc, parserContext) {
596
+ function _parseAssociationProperty(foreignReference, associationNode, parserContext) {
598
597
  const associationProperty = {};
599
598
  let foreignKeys;
600
599
  // var foreignReference = associationNode.$Type;
@@ -626,7 +625,7 @@ function _parseAssociationProperty(foreignReference, associationNode, mockServer
626
625
  );
627
626
  }
628
627
 
629
- if (mockServerUc && entityTypeMapping) {
628
+ if (parserContext.mockServerUc && entityTypeMapping) {
630
629
  if (entityTypeMapping.length > 1) {
631
630
  for (let j = 0; j < entityTypeMapping.length; j++) {
632
631
  if (entityTypeMapping[j] === foreignReference) {
@@ -712,7 +711,7 @@ function _checkIsStructureTypeAndReturnDataKind(dataType, contentObject, element
712
711
  * @param {Object} elementObj
713
712
  * @param {Object} parserContext
714
713
  */
715
- function _parsePropertyContent(csnObj, elementObj, mockServerUc, parserContext) {
714
+ function _parsePropertyContent(csnObj, elementObj, parserContext) {
716
715
  let contentObj = {};
717
716
  const isPrimaryKey = true;
718
717
  let dataType, isPrimitiveType, keySet = [];
@@ -748,17 +747,17 @@ function _parsePropertyContent(csnObj, elementObj, mockServerUc, parserContext)
748
747
  if (['EnumType', 'TypeDefinition'].includes(dataKind)) {
749
748
  csnObj.elements[objKey] = _generateStructuredDataTypeCsn(dataType, contentObj,
750
749
  (keySet.includes(dataType) ? isPrimaryKey : !isPrimaryKey),
751
- dataKind, 'property', mockServerUc, parserContext
750
+ dataKind, 'property', parserContext
752
751
  );
753
752
  }
754
753
  else {
755
754
  csnObj.elements[objKey] = _generateStructuredDataTypeCsn(dataType, contentObj,
756
- !isPrimaryKey, dataKind, 'property', mockServerUc, parserContext
755
+ !isPrimaryKey, dataKind, 'property', parserContext
757
756
  );
758
757
  }
759
758
  }
760
759
  else if (contentKind === 'NavigationProperty') {
761
- csnObj.elements[objKey] = _parseAssociationProperty(objKey, elementObj[objKey], mockServerUc, parserContext);
760
+ csnObj.elements[objKey] = _parseAssociationProperty(objKey, elementObj[objKey], parserContext);
762
761
  }
763
762
  }
764
763
  }
@@ -837,7 +836,7 @@ function _captureOpenTypes(fqName, csnObj, elementObj, isEntity, mockServerUc, p
837
836
  }
838
837
  }
839
838
 
840
- function _generateCSNForEntityType(ignorePersistenceSkip, mockServerUc, entityList, parserContext) {
839
+ function _generateCSNForEntityType(ignorePersistenceSkip, entityList, parserContext) {
841
840
  const csnEntity = {};
842
841
  let isEntity = true;
843
842
  entityList.forEach(entityElement => {
@@ -851,12 +850,12 @@ function _generateCSNForEntityType(ignorePersistenceSkip, mockServerUc, entityLi
851
850
  csnEntity[entityName]['@cds.persistence.skip'] = true;
852
851
  }
853
852
 
854
- _captureOpenTypes(entityName, csnEntity[entityName], entityElement[entityName], isEntity, mockServerUc, parserContext);
853
+ _captureOpenTypes(entityName, csnEntity[entityName], entityElement[entityName], isEntity, parserContext.mockServerUc, parserContext);
855
854
  _captureAnnotationWithinElement(entityElement[entityName], csnEntity[entityName], parserContext);
856
855
 
857
856
  csnEntity[entityName].elements = {};
858
857
 
859
- _parsePropertyContent(csnEntity[entityName], entityElement[entityName], mockServerUc, parserContext);
858
+ _parsePropertyContent(csnEntity[entityName], entityElement[entityName], parserContext);
860
859
 
861
860
  // needs to be checked if this is necessary
862
861
  if (entityElement[entityName].$HasStream) {
@@ -871,7 +870,7 @@ function _generateCSNForEntityType(ignorePersistenceSkip, mockServerUc, entityLi
871
870
  return csnEntity;
872
871
  }
873
872
 
874
- function _parseCSNForEntityType(schemaData, ignorePersistenceSkip, mockServerUc, parserContext) {
873
+ function _parseCSNForEntityType(schemaData, ignorePersistenceSkip, parserContext) {
875
874
  let entitiesList = [];
876
875
  for (let fqName of parserContext.entityTypes) {
877
876
  let entity = {};
@@ -884,10 +883,10 @@ function _parseCSNForEntityType(schemaData, ignorePersistenceSkip, mockServerUc,
884
883
  }
885
884
  }
886
885
 
887
- return _generateCSNForEntityType(ignorePersistenceSkip, mockServerUc, entitiesList, parserContext);
886
+ return _generateCSNForEntityType(ignorePersistenceSkip, entitiesList, parserContext);
888
887
  }
889
888
 
890
- function _parseParameterAndReturnTypeContent(elementObject, mockServerUc, parserContext) {
889
+ function _parseParameterAndReturnTypeContent(elementObject, parserContext) {
891
890
  let dataType = elementObject.$Type;
892
891
  const isPrimitiveType = dataType.startsWith('Edm') ? true : false;
893
892
  const isPrimaryKey = true;
@@ -904,11 +903,11 @@ function _parseParameterAndReturnTypeContent(elementObject, mockServerUc, parser
904
903
  // structured type
905
904
  else {
906
905
  const dataKind = _checkIsStructureTypeAndReturnDataKind(dataType, elementObject, 'parameter', parserContext);
907
- return _generateStructuredDataTypeCsn(dataType, elementObject, !isPrimaryKey, dataKind, 'parameter', mockServerUc, parserContext);
906
+ return _generateStructuredDataTypeCsn(dataType, elementObject, !isPrimaryKey, dataKind, 'parameter', parserContext);
908
907
  }
909
908
  }
910
909
 
911
- function _generateCSNForBoundedActionFunction(actionFunctionObject, kind, mockServerUc, parserContext) {
910
+ function _generateCSNForBoundedActionFunction(actionFunctionObject, kind, parserContext) {
912
911
  const csnObj = {};
913
912
  const isBounded = actionFunctionObject.$IsBound;
914
913
  const parameters = actionFunctionObject.$Parameter;
@@ -922,7 +921,7 @@ function _generateCSNForBoundedActionFunction(actionFunctionObject, kind, mockSe
922
921
 
923
922
  for (let index = 0; index < parameters.length; index++) {
924
923
  let isCollection = parameters[index].$Collection;
925
- csnObj.params[parameters[index].$Name] = _parseParameterAndReturnTypeContent(parameters[index], mockServerUc, parserContext);
924
+ csnObj.params[parameters[index].$Name] = _parseParameterAndReturnTypeContent(parameters[index], parserContext);
926
925
  /**
927
926
  * binding parameter handling - only first parameter will contain the binding
928
927
  * parameter information, so only make change to the first parameter information.
@@ -940,13 +939,13 @@ function _generateCSNForBoundedActionFunction(actionFunctionObject, kind, mockSe
940
939
  }
941
940
  }
942
941
  if (returnType) {
943
- csnObj.returns = _parseParameterAndReturnTypeContent(returnType, mockServerUc, parserContext);
942
+ csnObj.returns = _parseParameterAndReturnTypeContent(returnType, parserContext);
944
943
  }
945
944
 
946
945
  return csnObj;
947
946
  }
948
947
 
949
- function _parseBoundedActionFunction(schemaData, csnObj, kind, mockServerUc, parserContext) {
948
+ function _parseBoundedActionFunction(schemaData, csnObj, kind, parserContext) {
950
949
  const boundedObject = (kind === 'action') ? parserContext.entityToBoundedActions : parserContext.entityToBoundedFunctions;
951
950
 
952
951
  Object.keys(boundedObject).forEach(fqEntityName => {
@@ -960,14 +959,14 @@ function _parseBoundedActionFunction(schemaData, csnObj, kind, mockServerUc, par
960
959
  }
961
960
  Object.keys(actionFunctionObjectList).forEach(actionFunctionName => {
962
961
  csnObj[fqEntityName].actions[actionFunctionName] = _generateCSNForBoundedActionFunction(
963
- actionFunctionObjectList[actionFunctionName], kind, mockServerUc, parserContext
962
+ actionFunctionObjectList[actionFunctionName], kind, parserContext
964
963
  );
965
964
  });
966
965
  }
967
966
  });
968
967
  }
969
968
 
970
- function _parseUnBoundedActionFunction(schemaData, kind, mockServerUc, parserContext) {
969
+ function _parseUnBoundedActionFunction(schemaData, kind, parserContext) {
971
970
  const unBoundedObject = (kind === 'action') ? parserContext.unboundedActions : parserContext.unboundedFunctions;
972
971
  const csnObj = {};
973
972
 
@@ -988,11 +987,11 @@ function _parseUnBoundedActionFunction(schemaData, kind, mockServerUc, parserCon
988
987
  csnObj[fqName].params = {};
989
988
 
990
989
  for (let paramObj of parameters) {
991
- csnObj[fqName].params[paramObj.$Name] = _parseParameterAndReturnTypeContent(paramObj, mockServerUc, parserContext);
990
+ csnObj[fqName].params[paramObj.$Name] = _parseParameterAndReturnTypeContent(paramObj, parserContext);
992
991
  }
993
992
  }
994
993
  if (returnType) {
995
- csnObj[fqName].returns = _parseParameterAndReturnTypeContent(returnType, mockServerUc, parserContext);
994
+ csnObj[fqName].returns = _parseParameterAndReturnTypeContent(returnType, parserContext);
996
995
  }
997
996
  }
998
997
  });
@@ -1000,7 +999,7 @@ function _parseUnBoundedActionFunction(schemaData, kind, mockServerUc, parserCon
1000
999
  return csnObj;
1001
1000
  }
1002
1001
 
1003
- function _parserCSNForComplexType(schemaData, mockServerUc, parserContext) {
1002
+ function _parserCSNForComplexType(schemaData, parserContext) {
1004
1003
  const complexCsn = {};
1005
1004
  const isEntity = true;
1006
1005
 
@@ -1014,9 +1013,9 @@ function _parserCSNForComplexType(schemaData, mockServerUc, parserContext) {
1014
1013
  complexCsn[fqName]['@cds.external'] = true;
1015
1014
  complexCsn[fqName].elements = {};
1016
1015
  // inheritance handling
1017
- _captureOpenTypes(fqName, complexCsn[fqName], complexObj, !isEntity, !mockServerUc, parserContext);
1016
+ _captureOpenTypes(fqName, complexCsn[fqName], complexObj, !isEntity, !parserContext.mockServerUc, parserContext);
1018
1017
  _captureAnnotationWithinElement(complexObj, complexCsn[fqName], parserContext);
1019
- _parsePropertyContent(complexCsn[fqName], complexObj, mockServerUc, parserContext);
1018
+ _parsePropertyContent(complexCsn[fqName], complexObj, parserContext);
1020
1019
  }
1021
1020
  }
1022
1021
  // add @open annotations
@@ -1102,7 +1101,7 @@ function _resolveEntityContainerAnnotationTarget(targetPath, csnDefs, hasPropert
1102
1101
  /**
1103
1102
  * format: <schemaName_or_Alias><EntityContainerName>/<ContainerElement>
1104
1103
  * <schemaName_or_Alias><EntityContainerName>/<ContainerElement>/...
1105
- *
1104
+ *
1106
1105
  * needs to be handled without 'EntityContainerName'
1107
1106
  */
1108
1107
  if (hasProperty) {
@@ -1167,7 +1166,7 @@ function _resolveAnnotationTarget(targetPath, csnDefs, parserContext) {
1167
1166
  const indexOfOpenBrace = targetPath.indexOf('(');
1168
1167
  const hasPropOrParam = (indexOfSlash > 0);
1169
1168
  let elemNameList, fqName;
1170
-
1169
+
1171
1170
  // Case 1: Direct path
1172
1171
  if (indexOfOpenBrace === -1 && indexOfSlash === -1) {
1173
1172
  fqName = _resolveAliasedElementName(targetPath, parserContext);
@@ -1224,7 +1223,7 @@ function _parseEntityContainer(csnDefs, entityContainerElements, parserContext)
1224
1223
  entityContainerElementNames.forEach(ecElement => {
1225
1224
  if (entityContainerElements[ecElement] instanceof Object) {
1226
1225
  let definitionRefName, kind;
1227
-
1226
+
1228
1227
  if (entityContainerElements[ecElement].$Action) {
1229
1228
  definitionRefName = entityContainerElements[ecElement].$Action;
1230
1229
  kind = 'action';
@@ -1245,7 +1244,7 @@ function _parseEntityContainer(csnDefs, entityContainerElements, parserContext)
1245
1244
  /**
1246
1245
  * For now we don't support the collision between entitycontainer element name
1247
1246
  * and any of the schema elemetents like entitytype, complextype, etc.
1248
- * TODO: In future we might have to support it.
1247
+ * TODO: In future we might have to support it.
1249
1248
  */
1250
1249
  if (csnDefs[fqElementName] && csnDefs[fqElementName].kind !== kind) {
1251
1250
  throw new Error(messages.ELEMENT_NAME_COLLISION + ecElement);
@@ -1315,7 +1314,7 @@ function _collectAllParameters(dataObjList) {
1315
1314
  * @param {String} fqName, fully qualified name
1316
1315
  * @param {List<Object>} schemaDataList
1317
1316
  * @param {Object} parserContext
1318
- *
1317
+ *
1319
1318
  * Scenarios:
1320
1319
  * 1. UnBounded Actions can't have collision. Action name must be unique.
1321
1320
  * 2. UnBounded Functions can have collision; capture the max number of parameters.
@@ -1366,7 +1365,7 @@ function _collectUnboundedActionFunction(schemaDataList, parserContext) {
1366
1365
  * @param {String} elementName
1367
1366
  * @param {List<Object>} elementDataList, bounded action/function details
1368
1367
  * @param {Object} parserContext
1369
- *
1368
+ *
1370
1369
  * Scenarios for bounded actions, functions:
1371
1370
  * 1. Actions with same name and binding parameter type can't have collision.
1372
1371
  * 2. Functions can have collision and we will capture the max number of parameters.
@@ -1472,7 +1471,7 @@ function _collectSchemaElements(edmxAsJson, schemaDataList, parserContext) {
1472
1471
  * we only have a single entity container
1473
1472
  */
1474
1473
  if (currNamespace === parserContext.primarySchema) {
1475
- Object.keys(schemaData.$Annotations).forEach(annotationTarget => {
1474
+ Object.keys(schemaData.$Annotations).forEach(annotationTarget => {
1476
1475
  if (annotationTarget.includes(parserContext.entityContainerName)) {
1477
1476
  parserContext.entityContainerAnnotations[annotationTarget] = schemaData.$Annotations[annotationTarget];
1478
1477
  /**
@@ -1489,7 +1488,8 @@ function _collectSchemaElements(edmxAsJson, schemaDataList, parserContext) {
1489
1488
  }
1490
1489
  }
1491
1490
 
1492
- function _preProcess(edmxAsJson, mockServerUc, parserContext) {
1491
+ function _preProcess(edmxAsJson, parserContext, importerContext) {
1492
+ _collectPrimarySchemaContext(edmxAsJson, parserContext, importerContext);
1493
1493
  let schemaDataList = [], indexOfSchema = 0;
1494
1494
 
1495
1495
  Object.keys(edmxAsJson).forEach(schemaName => {
@@ -1505,7 +1505,7 @@ function _preProcess(edmxAsJson, mockServerUc, parserContext) {
1505
1505
  indexOfSchema++;
1506
1506
  }
1507
1507
  // if mock server use case & traversing primary schema, collect relevant mappings
1508
- if (mockServerUc && schemaName === parserContext.primarySchema) {
1508
+ if (parserContext.mockServerUc && schemaName === parserContext.primarySchema) {
1509
1509
  let entityContainerData = schemaData[parserContext.entityContainerName];
1510
1510
  Object.keys(entityContainerData).forEach(elementName => {
1511
1511
  let elementObj = entityContainerData[elementName];
@@ -1531,18 +1531,27 @@ function _preProcess(edmxAsJson, mockServerUc, parserContext) {
1531
1531
  }
1532
1532
  });
1533
1533
 
1534
+ // if mockServerUc='true' and EntityContainer has no content, we set the value to false
1535
+ if (parserContext.mockServerUc &&
1536
+ parserContext.entityToEntitySetMap._.size === 0 &&
1537
+ parserContext.entityToSingletonMap._.size === 0 &&
1538
+ parserContext.actionToActionImportMap._.size === 0 &&
1539
+ parserContext.functionToFunctionImportMap._.size === 0) {
1540
+ parserContext.mockServerUc = false;
1541
+ }
1542
+
1534
1543
  _collectSchemaElements(edmxAsJson, schemaDataList, parserContext);
1535
1544
 
1536
1545
  return schemaDataList;
1537
1546
  }
1538
1547
 
1539
- function _generateCSN(edmxAsJson, ignorePersistenceSkip, mockServerUc, parserContext) {
1548
+ function _generateCSN(edmxAsJson, ignorePersistenceSkip, parserContext, importerContext) {
1540
1549
  let csn = {};
1541
1550
  csn.meta = {};
1542
1551
  csn.meta.creator = 'cds-dk ' + versionInfo;
1543
1552
  csn.$version = '2.0';
1544
1553
  csn.definitions = {};
1545
- let schemaDataList = _preProcess(edmxAsJson, mockServerUc, parserContext);
1554
+ let schemaDataList = _preProcess(edmxAsJson, parserContext, importerContext);
1546
1555
 
1547
1556
  for (let schemaData of schemaDataList) {
1548
1557
  // Step 1: parse all type definition
@@ -1550,15 +1559,15 @@ function _generateCSN(edmxAsJson, ignorePersistenceSkip, mockServerUc, parserCon
1550
1559
  // Step 2: parse all enum types
1551
1560
  csn.definitions = Object.assign(_parseCSNForEnumType(schemaData, parserContext), csn.definitions);
1552
1561
  // Step 3: parse all complex types
1553
- csn.definitions = Object.assign(_parserCSNForComplexType(schemaData, mockServerUc, parserContext), csn.definitions);
1562
+ csn.definitions = Object.assign(_parserCSNForComplexType(schemaData, parserContext), csn.definitions);
1554
1563
  // Step 4: parse all entity type
1555
- csn.definitions = Object.assign(_parseCSNForEntityType(schemaData, ignorePersistenceSkip, mockServerUc, parserContext), csn.definitions);
1564
+ csn.definitions = Object.assign(_parseCSNForEntityType(schemaData, ignorePersistenceSkip, parserContext), csn.definitions);
1556
1565
  // Step 5: parse all bounded action & function
1557
- _parseBoundedActionFunction(schemaData, csn.definitions, 'action', mockServerUc, parserContext);
1558
- _parseBoundedActionFunction(schemaData, csn.definitions, 'function', mockServerUc, parserContext);
1566
+ _parseBoundedActionFunction(schemaData, csn.definitions, 'action', parserContext);
1567
+ _parseBoundedActionFunction(schemaData, csn.definitions, 'function', parserContext);
1559
1568
  // Step 6: parse all unbounded action & function
1560
- csn.definitions = Object.assign(_parseUnBoundedActionFunction(schemaData, 'action', mockServerUc, parserContext), csn.definitions);
1561
- csn.definitions = Object.assign(_parseUnBoundedActionFunction(schemaData, 'function', mockServerUc, parserContext), csn.definitions);
1569
+ csn.definitions = Object.assign(_parseUnBoundedActionFunction(schemaData, 'action', parserContext), csn.definitions);
1570
+ csn.definitions = Object.assign(_parseUnBoundedActionFunction(schemaData, 'function', parserContext), csn.definitions);
1562
1571
  // Step 7: parse all annotations
1563
1572
  if (schemaData.$Annotations) {
1564
1573
  _parseAnnotations(schemaData.$Annotations, csn.definitions, parserContext);
@@ -1566,7 +1575,7 @@ function _generateCSN(edmxAsJson, ignorePersistenceSkip, mockServerUc, parserCon
1566
1575
  }
1567
1576
 
1568
1577
  // add Service object and EntityContainer items only if it is mock server use case
1569
- if (mockServerUc) {
1578
+ if (parserContext.mockServerUc) {
1570
1579
  csn.definitions[parserContext.primarySchema] = {};
1571
1580
  csn.definitions[parserContext.primarySchema].kind = 'service';
1572
1581
  csn.definitions[parserContext.primarySchema]['@cds.external'] = true;
@@ -1580,7 +1589,7 @@ function _generateCSN(edmxAsJson, ignorePersistenceSkip, mockServerUc, parserCon
1580
1589
  return JSON.stringify(csn, null, 4);
1581
1590
  }
1582
1591
 
1583
- function _generateEDMX2JSON(edmx, name_space, parserContext, context) {
1592
+ function _generateEDMX2JSON(edmx, name_space) {
1584
1593
  return new Promise(function getJson(resolve, reject) {
1585
1594
  try {
1586
1595
  const inputBuffer = edmx;
@@ -1590,9 +1599,7 @@ function _generateEDMX2JSON(edmx, name_space, parserContext, context) {
1590
1599
  if (missingReferencedDocuments?.length > 0) {
1591
1600
  console.log(missingReferencedDocuments); // eslint-disable-line no-console
1592
1601
  }
1593
- if (_isValidJSON(json, parserContext, context)) {
1594
- resolve(json);
1595
- }
1602
+ resolve(json);
1596
1603
  });
1597
1604
  } catch (err) {
1598
1605
  reject(err);
@@ -1600,37 +1607,34 @@ function _generateEDMX2JSON(edmx, name_space, parserContext, context) {
1600
1607
  });
1601
1608
  }
1602
1609
 
1603
- async function getEdmxv4CSN(edmx, ignorePersistenceSkip, mockServerUc, context) {
1610
+ async function getEdmxv4CSN(edmx, ignorePersistenceSkip, mockServerUc, importerContext) {
1604
1611
  let csn;
1605
1612
  let edmjConverted;
1606
1613
  let name_space = [];
1607
1614
 
1608
1615
  const parserContext = {};
1609
- _initialize(parserContext);
1616
+ _initialize(parserContext, mockServerUc);
1610
1617
 
1611
- if (context.include_all_namespaces) {
1618
+ if (importerContext.include_all_namespaces) {
1612
1619
  name_space.push(true);
1613
1620
  }
1614
1621
  else {
1615
- name_space = context.namespaces;
1622
+ name_space = importerContext.namespaces;
1616
1623
  }
1617
1624
 
1618
1625
  if (_isJson(edmx)) {
1619
1626
  return new Promise(function getCsn(resolve, reject) {
1620
1627
  try {
1621
1628
  edmjConverted = JSON.parse(edmx);
1622
- if (_isValidJSON(edmjConverted, parserContext, context)) {
1623
- csn = _generateCSN(edmjConverted, ignorePersistenceSkip, mockServerUc, parserContext);
1624
- if (csn) resolve(csn);
1625
- }
1629
+ csn = _generateCSN(edmjConverted, ignorePersistenceSkip, parserContext, importerContext);
1630
+ if (csn) resolve(csn);
1626
1631
  } catch (err) {
1627
1632
  reject(err);
1628
1633
  }
1629
1634
  });
1630
1635
  }
1631
- const edmj = await _generateEDMX2JSON(edmx, name_space, parserContext, context);
1632
-
1633
- return _generateCSN(edmj, ignorePersistenceSkip, mockServerUc, parserContext);
1636
+ const edmj = await _generateEDMX2JSON(edmx, name_space);
1637
+ return _generateCSN(edmj, ignorePersistenceSkip, parserContext, importerContext);
1634
1638
  }
1635
1639
 
1636
1640
  module.exports = {
@@ -1,6 +1,6 @@
1
1
  const os = require('os');
2
2
 
3
- const MAVEN_ARCHETYPE_VERSION = '2.0.2';
3
+ const MAVEN_ARCHETYPE_VERSION = '2.1.0';
4
4
 
5
5
  const constants = {
6
6
  IS_WIN: (os.platform() === 'win32'),