@sap/cds-dk 7.0.3 → 7.1.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.
Files changed (42) hide show
  1. package/bin/bind.js +5 -6
  2. package/bin/build.js +2 -7
  3. package/bin/cds.js +0 -4
  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 +9 -22
  10. package/lib/build/buildTaskFactory.js +18 -27
  11. package/lib/build/index.js +12 -3
  12. package/lib/build/provider/buildTaskProviderInternal.js +23 -15
  13. package/lib/build/provider/mtx/index.js +8 -2
  14. package/lib/build/util.js +13 -0
  15. package/lib/client/activate.js +7 -7
  16. package/lib/client/auth_manager.js +5 -5
  17. package/lib/client/base_command.js +5 -5
  18. package/lib/client/extend.js +2 -2
  19. package/lib/client/helper/logging.js +7 -2
  20. package/lib/client/params.js +2 -3
  21. package/lib/client/pull.js +3 -3
  22. package/lib/client/push.js +3 -3
  23. package/lib/client/settings_manager.js +7 -8
  24. package/lib/client/tenant_action.js +3 -3
  25. package/lib/deploy/to-hana/hana.js +1 -2
  26. package/lib/import/common.js +3 -0
  27. package/lib/import/message.js +2 -1
  28. package/lib/import/odata/v4parser.js +85 -95
  29. package/lib/init/index.js +24 -11
  30. package/lib/init/template/cf-manifest/files/manifest.yml.hbs +1 -1
  31. package/lib/init/template/data/index.js +2 -3
  32. package/lib/init/template/lint/index.js +5 -6
  33. package/lib/init/template/nodejs/index.js +2 -3
  34. package/lib/init/template/pipeline/index.js +1 -2
  35. package/lib/init/util/indent.js +1 -1
  36. package/lib/init/util/merge.js +3 -3
  37. package/lib/init/util/mvn.js +17 -22
  38. package/lib/util/cfUtil.js +1 -2
  39. package/npm-shrinkwrap.json +353 -300
  40. package/package.json +1 -1
  41. package/lib/client/helper/errors.js +0 -26
  42. 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
 
@@ -213,7 +198,7 @@ function _updateElementObjectForDefaultValue(dataTypeObj, defaultvalue) {
213
198
  }
214
199
 
215
200
  function _updateDataTypeObjectForMaxLength(dataTypeObj, propertyDataType, maxLength) {
216
- const mappedValue = edmToCdsTypeMappingWithMaxLength[propertyDataType];
201
+ const mappedValue = edmToCdsTypeMappingWithMaxLength[propertyDataType];
217
202
 
218
203
  if (mappedValue) {
219
204
  dataTypeObj.type = mappedValue
@@ -301,7 +286,7 @@ function _resolveCoreTerm(annotationTerm, annotationTermObject, csnDefsTargetObj
301
286
  if (annotationTerm === "@Core.Description" || annotationTerm === "@Core.LongDescription") {
302
287
  // we don't capture `null` value for doc
303
288
  if (annotationTermObject === null) return;
304
-
289
+
305
290
  annotationTermObject = _replaceSpecialCharacters(annotationTermObject);
306
291
 
307
292
  if (csnDefsTargetObject.doc) {
@@ -372,7 +357,7 @@ function _parseCapabilitiesTerm(annotationTerm, annotationTermObject, csnDefsTar
372
357
  * For entries like:
373
358
  * <Annotation Term="Capabilities.FilterFunctions"> <Collection> <String>eq</String> <String>ne</String> </Collection> </Annotation>
374
359
  * <Annotation Term="Capabilities.DeleteRestrictions.Deletable" Bool="true"/>
375
- *
360
+ *
376
361
  * simply preserve the value as it is
377
362
  */
378
363
  if (annotationTermObject instanceof Array || !(annotationTermObject instanceof Object)) {
@@ -433,8 +418,8 @@ function _parseAnnotationTerms(annotationTerm, annotationTermObject, csnDefsTarg
433
418
  function _resolveAnotationTerm(schemaDataAnnotation, parserContext) {
434
419
  // Case 1: We have the Namespace and Alias for the vocabulary
435
420
  for (const [alias, namespace] of Object.entries(parserContext.vocabAliasToNamespace)) {
436
- if (schemaDataAnnotation.includes(alias)) {
437
- schemaDataAnnotation = schemaDataAnnotation.split(alias).join(known_vocabularies[namespace]);
421
+ if (schemaDataAnnotation.includes('@' + alias)) {
422
+ schemaDataAnnotation = schemaDataAnnotation.split('@' + alias).join('@' + known_vocabularies[namespace]);
438
423
  }
439
424
  }
440
425
  /**
@@ -452,10 +437,10 @@ function _resolveAnotationTerm(schemaDataAnnotation, parserContext) {
452
437
 
453
438
  /**
454
439
  * Capture all the annotation cases withtin an Element
455
- *
440
+ *
456
441
  * UnKnown term: <Annotation Term="Org.OData.ASDF.V1.qwe"/>
457
442
  * Known term: <Annotation Term="Org.OData.Measures.V1.Unit" String="Centimeters"/>
458
- *
443
+ *
459
444
  * if "--include-namespaces *" then we also capture for ABS and QWE
460
445
  * <TypeDefinition Name="TD_2" UnderlyingType="Edm.Int32" ABS:asdf="testing" QWE:qwe="testing"/>
461
446
  */
@@ -536,7 +521,7 @@ function _getEntityTypeMappedName(entityType, parserContext) {
536
521
  }
537
522
  }
538
523
 
539
- function _generateStructuredDataTypeCsn(dataType, propertyObject, isPrimaryKey, dataTypeKind, elementKind, mockServerUc, parserContext) {
524
+ function _generateStructuredDataTypeCsn(dataType, propertyObject, isPrimaryKey, dataTypeKind, elementKind, parserContext) {
540
525
  const dataTypeObj = {};
541
526
  const isCollection = propertyObject.$Collection;
542
527
  const nullable = propertyObject.$Nullable;
@@ -558,7 +543,7 @@ function _generateStructuredDataTypeCsn(dataType, propertyObject, isPrimaryKey,
558
543
  }
559
544
 
560
545
  // if dataTypeKind is EntityType, also check for mapped entity name
561
- if (mockServerUc && dataTypeKind === 'EntityType') {
546
+ if (parserContext.mockServerUc && dataTypeKind === 'EntityType') {
562
547
  // propertyDataType is resolved fully qualified name
563
548
  if (parserContext.entityToEntitySetMap?.get(propertyDataType)) {
564
549
  propertyDataType = _getEntityTypeMappedName(propertyDataType, parserContext);
@@ -578,9 +563,9 @@ function _generateStructuredDataTypeCsn(dataType, propertyObject, isPrimaryKey,
578
563
  }
579
564
  /**
580
565
  * only Primitive type and EnumType can have DefaultValue facet as per documentation
581
- * but compiler accepts it for TypeDefintion and ComplexType as well,
566
+ * but compiler accepts it for TypeDefintion and ComplexType as well,
582
567
  * do we also need to handle it for TypeDefintion and ComplexType?
583
- *
568
+ *
584
569
  * For parameters, default value is added via OptionalParamter Annotation
585
570
  */
586
571
  if (defaultvalue && dataTypeKind === 'EnumType' && elementKind === 'property') {
@@ -594,7 +579,7 @@ function _generateStructuredDataTypeCsn(dataType, propertyObject, isPrimaryKey,
594
579
  return dataTypeObj;
595
580
  }
596
581
 
597
- function _parseAssociationProperty(foreignReference, associationNode, mockServerUc, parserContext) {
582
+ function _parseAssociationProperty(foreignReference, associationNode, parserContext) {
598
583
  const associationProperty = {};
599
584
  let foreignKeys;
600
585
  // var foreignReference = associationNode.$Type;
@@ -626,7 +611,7 @@ function _parseAssociationProperty(foreignReference, associationNode, mockServer
626
611
  );
627
612
  }
628
613
 
629
- if (mockServerUc && entityTypeMapping) {
614
+ if (parserContext.mockServerUc && entityTypeMapping) {
630
615
  if (entityTypeMapping.length > 1) {
631
616
  for (let j = 0; j < entityTypeMapping.length; j++) {
632
617
  if (entityTypeMapping[j] === foreignReference) {
@@ -712,7 +697,7 @@ function _checkIsStructureTypeAndReturnDataKind(dataType, contentObject, element
712
697
  * @param {Object} elementObj
713
698
  * @param {Object} parserContext
714
699
  */
715
- function _parsePropertyContent(csnObj, elementObj, mockServerUc, parserContext) {
700
+ function _parsePropertyContent(csnObj, elementObj, parserContext) {
716
701
  let contentObj = {};
717
702
  const isPrimaryKey = true;
718
703
  let dataType, isPrimitiveType, keySet = [];
@@ -748,17 +733,17 @@ function _parsePropertyContent(csnObj, elementObj, mockServerUc, parserContext)
748
733
  if (['EnumType', 'TypeDefinition'].includes(dataKind)) {
749
734
  csnObj.elements[objKey] = _generateStructuredDataTypeCsn(dataType, contentObj,
750
735
  (keySet.includes(dataType) ? isPrimaryKey : !isPrimaryKey),
751
- dataKind, 'property', mockServerUc, parserContext
736
+ dataKind, 'property', parserContext
752
737
  );
753
738
  }
754
739
  else {
755
740
  csnObj.elements[objKey] = _generateStructuredDataTypeCsn(dataType, contentObj,
756
- !isPrimaryKey, dataKind, 'property', mockServerUc, parserContext
741
+ !isPrimaryKey, dataKind, 'property', parserContext
757
742
  );
758
743
  }
759
744
  }
760
745
  else if (contentKind === 'NavigationProperty') {
761
- csnObj.elements[objKey] = _parseAssociationProperty(objKey, elementObj[objKey], mockServerUc, parserContext);
746
+ csnObj.elements[objKey] = _parseAssociationProperty(objKey, elementObj[objKey], parserContext);
762
747
  }
763
748
  }
764
749
  }
@@ -837,7 +822,7 @@ function _captureOpenTypes(fqName, csnObj, elementObj, isEntity, mockServerUc, p
837
822
  }
838
823
  }
839
824
 
840
- function _generateCSNForEntityType(ignorePersistenceSkip, mockServerUc, entityList, parserContext) {
825
+ function _generateCSNForEntityType(ignorePersistenceSkip, entityList, parserContext) {
841
826
  const csnEntity = {};
842
827
  let isEntity = true;
843
828
  entityList.forEach(entityElement => {
@@ -851,12 +836,12 @@ function _generateCSNForEntityType(ignorePersistenceSkip, mockServerUc, entityLi
851
836
  csnEntity[entityName]['@cds.persistence.skip'] = true;
852
837
  }
853
838
 
854
- _captureOpenTypes(entityName, csnEntity[entityName], entityElement[entityName], isEntity, mockServerUc, parserContext);
839
+ _captureOpenTypes(entityName, csnEntity[entityName], entityElement[entityName], isEntity, parserContext.mockServerUc, parserContext);
855
840
  _captureAnnotationWithinElement(entityElement[entityName], csnEntity[entityName], parserContext);
856
841
 
857
842
  csnEntity[entityName].elements = {};
858
843
 
859
- _parsePropertyContent(csnEntity[entityName], entityElement[entityName], mockServerUc, parserContext);
844
+ _parsePropertyContent(csnEntity[entityName], entityElement[entityName], parserContext);
860
845
 
861
846
  // needs to be checked if this is necessary
862
847
  if (entityElement[entityName].$HasStream) {
@@ -871,7 +856,7 @@ function _generateCSNForEntityType(ignorePersistenceSkip, mockServerUc, entityLi
871
856
  return csnEntity;
872
857
  }
873
858
 
874
- function _parseCSNForEntityType(schemaData, ignorePersistenceSkip, mockServerUc, parserContext) {
859
+ function _parseCSNForEntityType(schemaData, ignorePersistenceSkip, parserContext) {
875
860
  let entitiesList = [];
876
861
  for (let fqName of parserContext.entityTypes) {
877
862
  let entity = {};
@@ -884,10 +869,10 @@ function _parseCSNForEntityType(schemaData, ignorePersistenceSkip, mockServerUc,
884
869
  }
885
870
  }
886
871
 
887
- return _generateCSNForEntityType(ignorePersistenceSkip, mockServerUc, entitiesList, parserContext);
872
+ return _generateCSNForEntityType(ignorePersistenceSkip, entitiesList, parserContext);
888
873
  }
889
874
 
890
- function _parseParameterAndReturnTypeContent(elementObject, mockServerUc, parserContext) {
875
+ function _parseParameterAndReturnTypeContent(elementObject, parserContext) {
891
876
  let dataType = elementObject.$Type;
892
877
  const isPrimitiveType = dataType.startsWith('Edm') ? true : false;
893
878
  const isPrimaryKey = true;
@@ -904,11 +889,11 @@ function _parseParameterAndReturnTypeContent(elementObject, mockServerUc, parser
904
889
  // structured type
905
890
  else {
906
891
  const dataKind = _checkIsStructureTypeAndReturnDataKind(dataType, elementObject, 'parameter', parserContext);
907
- return _generateStructuredDataTypeCsn(dataType, elementObject, !isPrimaryKey, dataKind, 'parameter', mockServerUc, parserContext);
892
+ return _generateStructuredDataTypeCsn(dataType, elementObject, !isPrimaryKey, dataKind, 'parameter', parserContext);
908
893
  }
909
894
  }
910
895
 
911
- function _generateCSNForBoundedActionFunction(actionFunctionObject, kind, mockServerUc, parserContext) {
896
+ function _generateCSNForBoundedActionFunction(actionFunctionObject, kind, parserContext) {
912
897
  const csnObj = {};
913
898
  const isBounded = actionFunctionObject.$IsBound;
914
899
  const parameters = actionFunctionObject.$Parameter;
@@ -922,7 +907,7 @@ function _generateCSNForBoundedActionFunction(actionFunctionObject, kind, mockSe
922
907
 
923
908
  for (let index = 0; index < parameters.length; index++) {
924
909
  let isCollection = parameters[index].$Collection;
925
- csnObj.params[parameters[index].$Name] = _parseParameterAndReturnTypeContent(parameters[index], mockServerUc, parserContext);
910
+ csnObj.params[parameters[index].$Name] = _parseParameterAndReturnTypeContent(parameters[index], parserContext);
926
911
  /**
927
912
  * binding parameter handling - only first parameter will contain the binding
928
913
  * parameter information, so only make change to the first parameter information.
@@ -940,13 +925,13 @@ function _generateCSNForBoundedActionFunction(actionFunctionObject, kind, mockSe
940
925
  }
941
926
  }
942
927
  if (returnType) {
943
- csnObj.returns = _parseParameterAndReturnTypeContent(returnType, mockServerUc, parserContext);
928
+ csnObj.returns = _parseParameterAndReturnTypeContent(returnType, parserContext);
944
929
  }
945
930
 
946
931
  return csnObj;
947
932
  }
948
933
 
949
- function _parseBoundedActionFunction(schemaData, csnObj, kind, mockServerUc, parserContext) {
934
+ function _parseBoundedActionFunction(schemaData, csnObj, kind, parserContext) {
950
935
  const boundedObject = (kind === 'action') ? parserContext.entityToBoundedActions : parserContext.entityToBoundedFunctions;
951
936
 
952
937
  Object.keys(boundedObject).forEach(fqEntityName => {
@@ -960,14 +945,14 @@ function _parseBoundedActionFunction(schemaData, csnObj, kind, mockServerUc, par
960
945
  }
961
946
  Object.keys(actionFunctionObjectList).forEach(actionFunctionName => {
962
947
  csnObj[fqEntityName].actions[actionFunctionName] = _generateCSNForBoundedActionFunction(
963
- actionFunctionObjectList[actionFunctionName], kind, mockServerUc, parserContext
948
+ actionFunctionObjectList[actionFunctionName], kind, parserContext
964
949
  );
965
950
  });
966
951
  }
967
952
  });
968
953
  }
969
954
 
970
- function _parseUnBoundedActionFunction(schemaData, kind, mockServerUc, parserContext) {
955
+ function _parseUnBoundedActionFunction(schemaData, kind, parserContext) {
971
956
  const unBoundedObject = (kind === 'action') ? parserContext.unboundedActions : parserContext.unboundedFunctions;
972
957
  const csnObj = {};
973
958
 
@@ -988,11 +973,11 @@ function _parseUnBoundedActionFunction(schemaData, kind, mockServerUc, parserCon
988
973
  csnObj[fqName].params = {};
989
974
 
990
975
  for (let paramObj of parameters) {
991
- csnObj[fqName].params[paramObj.$Name] = _parseParameterAndReturnTypeContent(paramObj, mockServerUc, parserContext);
976
+ csnObj[fqName].params[paramObj.$Name] = _parseParameterAndReturnTypeContent(paramObj, parserContext);
992
977
  }
993
978
  }
994
979
  if (returnType) {
995
- csnObj[fqName].returns = _parseParameterAndReturnTypeContent(returnType, mockServerUc, parserContext);
980
+ csnObj[fqName].returns = _parseParameterAndReturnTypeContent(returnType, parserContext);
996
981
  }
997
982
  }
998
983
  });
@@ -1000,7 +985,7 @@ function _parseUnBoundedActionFunction(schemaData, kind, mockServerUc, parserCon
1000
985
  return csnObj;
1001
986
  }
1002
987
 
1003
- function _parserCSNForComplexType(schemaData, mockServerUc, parserContext) {
988
+ function _parserCSNForComplexType(schemaData, parserContext) {
1004
989
  const complexCsn = {};
1005
990
  const isEntity = true;
1006
991
 
@@ -1014,9 +999,9 @@ function _parserCSNForComplexType(schemaData, mockServerUc, parserContext) {
1014
999
  complexCsn[fqName]['@cds.external'] = true;
1015
1000
  complexCsn[fqName].elements = {};
1016
1001
  // inheritance handling
1017
- _captureOpenTypes(fqName, complexCsn[fqName], complexObj, !isEntity, !mockServerUc, parserContext);
1002
+ _captureOpenTypes(fqName, complexCsn[fqName], complexObj, !isEntity, !parserContext.mockServerUc, parserContext);
1018
1003
  _captureAnnotationWithinElement(complexObj, complexCsn[fqName], parserContext);
1019
- _parsePropertyContent(complexCsn[fqName], complexObj, mockServerUc, parserContext);
1004
+ _parsePropertyContent(complexCsn[fqName], complexObj, parserContext);
1020
1005
  }
1021
1006
  }
1022
1007
  // add @open annotations
@@ -1102,7 +1087,7 @@ function _resolveEntityContainerAnnotationTarget(targetPath, csnDefs, hasPropert
1102
1087
  /**
1103
1088
  * format: <schemaName_or_Alias><EntityContainerName>/<ContainerElement>
1104
1089
  * <schemaName_or_Alias><EntityContainerName>/<ContainerElement>/...
1105
- *
1090
+ *
1106
1091
  * needs to be handled without 'EntityContainerName'
1107
1092
  */
1108
1093
  if (hasProperty) {
@@ -1167,7 +1152,7 @@ function _resolveAnnotationTarget(targetPath, csnDefs, parserContext) {
1167
1152
  const indexOfOpenBrace = targetPath.indexOf('(');
1168
1153
  const hasPropOrParam = (indexOfSlash > 0);
1169
1154
  let elemNameList, fqName;
1170
-
1155
+
1171
1156
  // Case 1: Direct path
1172
1157
  if (indexOfOpenBrace === -1 && indexOfSlash === -1) {
1173
1158
  fqName = _resolveAliasedElementName(targetPath, parserContext);
@@ -1224,7 +1209,7 @@ function _parseEntityContainer(csnDefs, entityContainerElements, parserContext)
1224
1209
  entityContainerElementNames.forEach(ecElement => {
1225
1210
  if (entityContainerElements[ecElement] instanceof Object) {
1226
1211
  let definitionRefName, kind;
1227
-
1212
+
1228
1213
  if (entityContainerElements[ecElement].$Action) {
1229
1214
  definitionRefName = entityContainerElements[ecElement].$Action;
1230
1215
  kind = 'action';
@@ -1245,7 +1230,7 @@ function _parseEntityContainer(csnDefs, entityContainerElements, parserContext)
1245
1230
  /**
1246
1231
  * For now we don't support the collision between entitycontainer element name
1247
1232
  * and any of the schema elemetents like entitytype, complextype, etc.
1248
- * TODO: In future we might have to support it.
1233
+ * TODO: In future we might have to support it.
1249
1234
  */
1250
1235
  if (csnDefs[fqElementName] && csnDefs[fqElementName].kind !== kind) {
1251
1236
  throw new Error(messages.ELEMENT_NAME_COLLISION + ecElement);
@@ -1315,7 +1300,7 @@ function _collectAllParameters(dataObjList) {
1315
1300
  * @param {String} fqName, fully qualified name
1316
1301
  * @param {List<Object>} schemaDataList
1317
1302
  * @param {Object} parserContext
1318
- *
1303
+ *
1319
1304
  * Scenarios:
1320
1305
  * 1. UnBounded Actions can't have collision. Action name must be unique.
1321
1306
  * 2. UnBounded Functions can have collision; capture the max number of parameters.
@@ -1366,7 +1351,7 @@ function _collectUnboundedActionFunction(schemaDataList, parserContext) {
1366
1351
  * @param {String} elementName
1367
1352
  * @param {List<Object>} elementDataList, bounded action/function details
1368
1353
  * @param {Object} parserContext
1369
- *
1354
+ *
1370
1355
  * Scenarios for bounded actions, functions:
1371
1356
  * 1. Actions with same name and binding parameter type can't have collision.
1372
1357
  * 2. Functions can have collision and we will capture the max number of parameters.
@@ -1472,7 +1457,7 @@ function _collectSchemaElements(edmxAsJson, schemaDataList, parserContext) {
1472
1457
  * we only have a single entity container
1473
1458
  */
1474
1459
  if (currNamespace === parserContext.primarySchema) {
1475
- Object.keys(schemaData.$Annotations).forEach(annotationTarget => {
1460
+ Object.keys(schemaData.$Annotations).forEach(annotationTarget => {
1476
1461
  if (annotationTarget.includes(parserContext.entityContainerName)) {
1477
1462
  parserContext.entityContainerAnnotations[annotationTarget] = schemaData.$Annotations[annotationTarget];
1478
1463
  /**
@@ -1489,7 +1474,8 @@ function _collectSchemaElements(edmxAsJson, schemaDataList, parserContext) {
1489
1474
  }
1490
1475
  }
1491
1476
 
1492
- function _preProcess(edmxAsJson, mockServerUc, parserContext) {
1477
+ function _preProcess(edmxAsJson, parserContext, importerContext) {
1478
+ _collectPrimarySchemaContext(edmxAsJson, parserContext, importerContext);
1493
1479
  let schemaDataList = [], indexOfSchema = 0;
1494
1480
 
1495
1481
  Object.keys(edmxAsJson).forEach(schemaName => {
@@ -1505,7 +1491,7 @@ function _preProcess(edmxAsJson, mockServerUc, parserContext) {
1505
1491
  indexOfSchema++;
1506
1492
  }
1507
1493
  // if mock server use case & traversing primary schema, collect relevant mappings
1508
- if (mockServerUc && schemaName === parserContext.primarySchema) {
1494
+ if (parserContext.mockServerUc && schemaName === parserContext.primarySchema) {
1509
1495
  let entityContainerData = schemaData[parserContext.entityContainerName];
1510
1496
  Object.keys(entityContainerData).forEach(elementName => {
1511
1497
  let elementObj = entityContainerData[elementName];
@@ -1531,18 +1517,27 @@ function _preProcess(edmxAsJson, mockServerUc, parserContext) {
1531
1517
  }
1532
1518
  });
1533
1519
 
1520
+ // if mockServerUc='true' and EntityContainer has no content, we set the value to false
1521
+ if (parserContext.mockServerUc &&
1522
+ parserContext.entityToEntitySetMap._.size === 0 &&
1523
+ parserContext.entityToSingletonMap._.size === 0 &&
1524
+ parserContext.actionToActionImportMap._.size === 0 &&
1525
+ parserContext.functionToFunctionImportMap._.size === 0) {
1526
+ parserContext.mockServerUc = false;
1527
+ }
1528
+
1534
1529
  _collectSchemaElements(edmxAsJson, schemaDataList, parserContext);
1535
1530
 
1536
1531
  return schemaDataList;
1537
1532
  }
1538
1533
 
1539
- function _generateCSN(edmxAsJson, ignorePersistenceSkip, mockServerUc, parserContext) {
1534
+ function _generateCSN(edmxAsJson, ignorePersistenceSkip, parserContext, importerContext) {
1540
1535
  let csn = {};
1541
1536
  csn.meta = {};
1542
1537
  csn.meta.creator = 'cds-dk ' + versionInfo;
1543
1538
  csn.$version = '2.0';
1544
1539
  csn.definitions = {};
1545
- let schemaDataList = _preProcess(edmxAsJson, mockServerUc, parserContext);
1540
+ let schemaDataList = _preProcess(edmxAsJson, parserContext, importerContext);
1546
1541
 
1547
1542
  for (let schemaData of schemaDataList) {
1548
1543
  // Step 1: parse all type definition
@@ -1550,15 +1545,15 @@ function _generateCSN(edmxAsJson, ignorePersistenceSkip, mockServerUc, parserCon
1550
1545
  // Step 2: parse all enum types
1551
1546
  csn.definitions = Object.assign(_parseCSNForEnumType(schemaData, parserContext), csn.definitions);
1552
1547
  // Step 3: parse all complex types
1553
- csn.definitions = Object.assign(_parserCSNForComplexType(schemaData, mockServerUc, parserContext), csn.definitions);
1548
+ csn.definitions = Object.assign(_parserCSNForComplexType(schemaData, parserContext), csn.definitions);
1554
1549
  // Step 4: parse all entity type
1555
- csn.definitions = Object.assign(_parseCSNForEntityType(schemaData, ignorePersistenceSkip, mockServerUc, parserContext), csn.definitions);
1550
+ csn.definitions = Object.assign(_parseCSNForEntityType(schemaData, ignorePersistenceSkip, parserContext), csn.definitions);
1556
1551
  // Step 5: parse all bounded action & function
1557
- _parseBoundedActionFunction(schemaData, csn.definitions, 'action', mockServerUc, parserContext);
1558
- _parseBoundedActionFunction(schemaData, csn.definitions, 'function', mockServerUc, parserContext);
1552
+ _parseBoundedActionFunction(schemaData, csn.definitions, 'action', parserContext);
1553
+ _parseBoundedActionFunction(schemaData, csn.definitions, 'function', parserContext);
1559
1554
  // 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);
1555
+ csn.definitions = Object.assign(_parseUnBoundedActionFunction(schemaData, 'action', parserContext), csn.definitions);
1556
+ csn.definitions = Object.assign(_parseUnBoundedActionFunction(schemaData, 'function', parserContext), csn.definitions);
1562
1557
  // Step 7: parse all annotations
1563
1558
  if (schemaData.$Annotations) {
1564
1559
  _parseAnnotations(schemaData.$Annotations, csn.definitions, parserContext);
@@ -1566,7 +1561,7 @@ function _generateCSN(edmxAsJson, ignorePersistenceSkip, mockServerUc, parserCon
1566
1561
  }
1567
1562
 
1568
1563
  // add Service object and EntityContainer items only if it is mock server use case
1569
- if (mockServerUc) {
1564
+ if (parserContext.mockServerUc) {
1570
1565
  csn.definitions[parserContext.primarySchema] = {};
1571
1566
  csn.definitions[parserContext.primarySchema].kind = 'service';
1572
1567
  csn.definitions[parserContext.primarySchema]['@cds.external'] = true;
@@ -1580,7 +1575,7 @@ function _generateCSN(edmxAsJson, ignorePersistenceSkip, mockServerUc, parserCon
1580
1575
  return JSON.stringify(csn, null, 4);
1581
1576
  }
1582
1577
 
1583
- function _generateEDMX2JSON(edmx, name_space, parserContext, context) {
1578
+ function _generateEDMX2JSON(edmx, name_space) {
1584
1579
  return new Promise(function getJson(resolve, reject) {
1585
1580
  try {
1586
1581
  const inputBuffer = edmx;
@@ -1590,9 +1585,7 @@ function _generateEDMX2JSON(edmx, name_space, parserContext, context) {
1590
1585
  if (missingReferencedDocuments?.length > 0) {
1591
1586
  console.log(missingReferencedDocuments); // eslint-disable-line no-console
1592
1587
  }
1593
- if (_isValidJSON(json, parserContext, context)) {
1594
- resolve(json);
1595
- }
1588
+ resolve(json);
1596
1589
  });
1597
1590
  } catch (err) {
1598
1591
  reject(err);
@@ -1600,37 +1593,34 @@ function _generateEDMX2JSON(edmx, name_space, parserContext, context) {
1600
1593
  });
1601
1594
  }
1602
1595
 
1603
- async function getEdmxv4CSN(edmx, ignorePersistenceSkip, mockServerUc, context) {
1596
+ async function getEdmxv4CSN(edmx, ignorePersistenceSkip, mockServerUc, importerContext) {
1604
1597
  let csn;
1605
1598
  let edmjConverted;
1606
1599
  let name_space = [];
1607
1600
 
1608
1601
  const parserContext = {};
1609
- _initialize(parserContext);
1602
+ _initialize(parserContext, mockServerUc);
1610
1603
 
1611
- if (context.include_all_namespaces) {
1604
+ if (importerContext.include_all_namespaces) {
1612
1605
  name_space.push(true);
1613
1606
  }
1614
1607
  else {
1615
- name_space = context.namespaces;
1608
+ name_space = importerContext.namespaces;
1616
1609
  }
1617
1610
 
1618
1611
  if (_isJson(edmx)) {
1619
1612
  return new Promise(function getCsn(resolve, reject) {
1620
1613
  try {
1621
1614
  edmjConverted = JSON.parse(edmx);
1622
- if (_isValidJSON(edmjConverted, parserContext, context)) {
1623
- csn = _generateCSN(edmjConverted, ignorePersistenceSkip, mockServerUc, parserContext);
1624
- if (csn) resolve(csn);
1625
- }
1615
+ csn = _generateCSN(edmjConverted, ignorePersistenceSkip, parserContext, importerContext);
1616
+ if (csn) resolve(csn);
1626
1617
  } catch (err) {
1627
1618
  reject(err);
1628
1619
  }
1629
1620
  });
1630
1621
  }
1631
- const edmj = await _generateEDMX2JSON(edmx, name_space, parserContext, context);
1632
-
1633
- return _generateCSN(edmj, ignorePersistenceSkip, mockServerUc, parserContext);
1622
+ const edmj = await _generateEDMX2JSON(edmx, name_space);
1623
+ return _generateCSN(edmj, ignorePersistenceSkip, parserContext, importerContext);
1634
1624
  }
1635
1625
 
1636
1626
  module.exports = {
package/lib/init/index.js CHANGED
@@ -3,10 +3,9 @@ const path = require('path');
3
3
  const term = require('../util/term');
4
4
 
5
5
  const { OPTIONS, COMMAND_INIT, PROJECT_FILES, REGEX_PROJECT_NAME } = require('./constants')
6
- const { NODEJS, JAVA, HANA, MTA,PIPELINE, SAMPLES, CF_MANIFEST } = OPTIONS
6
+ const { NODEJS, JAVA, HANA, MTA,PIPELINE, TINY_SAMPLE, CF_MANIFEST } = OPTIONS
7
7
 
8
8
  const cds = require('../cds'), { exists, readdir } = cds.utils
9
- const LOG = console
10
9
  const DEBUG = /\b(y|all|cli)\b/.test(process.env.DEBUG) ? console.debug : undefined
11
10
 
12
11
  module.exports = class CDSGenerator {
@@ -28,7 +27,7 @@ module.exports = class CDSGenerator {
28
27
 
29
28
  return true;
30
29
  } catch (err) {
31
- return err.message;
30
+ return err;
32
31
  }
33
32
  },
34
33
  guiOptions: {
@@ -75,7 +74,7 @@ module.exports = class CDSGenerator {
75
74
  description: `Add sample content to your project.`,
76
75
  default: '',
77
76
  choices: [
78
- { name: 'Basic Sample Files', value: SAMPLES }
77
+ { name: 'Basic Sample Files', value: TINY_SAMPLE }
79
78
  ],
80
79
  multiple: true,
81
80
  target: 'add',
@@ -112,7 +111,19 @@ module.exports = class CDSGenerator {
112
111
  await this.stepEnd();
113
112
  }
114
113
 
115
- async stepInit(projectName) {
114
+ async stepInit(projectName, options) {
115
+
116
+ if (!cds.cli?.command) {
117
+ // called from CAP generator
118
+ cds.cli = {
119
+ command: COMMAND_INIT,
120
+ // keep caller independent from internal names
121
+ options: {
122
+ cwd: options.cwd,
123
+ add: options.add
124
+ }
125
+ }
126
+ }
116
127
 
117
128
  this._initialize(projectName);
118
129
  this._greetings();
@@ -133,13 +144,13 @@ module.exports = class CDSGenerator {
133
144
  if (cds.cli.command === COMMAND_INIT) {
134
145
  const relativeProjectPath = path.relative(this.cwd, cds.root)
135
146
  const folderName = relativeProjectPath ? `.${path.sep}${relativeProjectPath}` : 'current folder'
136
- LOG.info(`Creating new CAP project in ${term.bold(folderName)}\n`)
147
+ console.log(`Creating new CAP project in ${term.bold(folderName)}\n`)
137
148
  }
138
149
  if (cds.cli.options.for && typeof cds.cli.options.for !== 'string') {
139
150
  throw 'The --for argument must not be empty.'
140
151
  }
141
152
  if (cds.cli.options.force) {
142
- LOG.info(`Using '--force' ... existing files will be overwritten`)
153
+ console.log(`Using '--force' ... existing files will be overwritten`)
143
154
  }
144
155
  }
145
156
 
@@ -150,7 +161,7 @@ module.exports = class CDSGenerator {
150
161
  await this._fillTemplateList();
151
162
 
152
163
  for (const template of this.templateList) {
153
- LOG.info(`Adding feature '${template.name}'...`);
164
+ console.log(`Adding feature '${template.name}'...`);
154
165
  await template.run();
155
166
  await template.runDependentMerging();
156
167
  await template.runRelatedMerging();
@@ -158,9 +169,9 @@ module.exports = class CDSGenerator {
158
169
 
159
170
  if (cds.cli.command === COMMAND_INIT) {
160
171
  const relativeProjectPath = path.relative(this.cwd, cds.root)
161
- LOG.info(`\nSuccessfully created project. Continue with '${term.bold('cd '+relativeProjectPath)}'.\n`)
172
+ console.log(`\nSuccessfully created project. Continue with '${term.bold('cd '+relativeProjectPath)}'.\n`)
162
173
  } else {
163
- LOG.info(`\nSuccessfully added features to your project.`)
174
+ console.log(`\nSuccessfully added features to your project.`)
164
175
  }
165
176
  }
166
177
 
@@ -179,7 +190,7 @@ module.exports = class CDSGenerator {
179
190
  );
180
191
  const fuzzySearch = require('../../bin/util/fuzzySearch');
181
192
  const [bestMatch] = fuzzySearch(filename, entries);
182
- LOG.info(`Unknown facet '${term.bold(filename)}'. Did you mean ${term.bold(`cds add ${bestMatch}`)}?\n\nHaven't found the proper facet yet? Here are all supported facets:\n\n ${term.bold(entries.join('\n '))}\n`);
193
+ console.log(`Unknown facet '${term.bold(filename)}'. Did you mean ${term.bold(`cds add ${bestMatch}`)}?\n\nHaven't found the proper facet yet? Here are all supported facets:\n\n ${term.bold(entries.join('\n '))}\n`);
183
194
  process.exit(1);
184
195
  }
185
196
  throw err;
@@ -189,6 +200,7 @@ module.exports = class CDSGenerator {
189
200
  async _fillTemplateList() {
190
201
  const templates = new Map
191
202
  const { command, options, argv } = cds.cli
203
+
192
204
  const facets = command === COMMAND_INIT ? options.add : new Set(argv[0].split(','))
193
205
 
194
206
  for (let facet of facets) {
@@ -216,6 +228,7 @@ module.exports = class CDSGenerator {
216
228
  DEBUG?.(`Features: ${this.templateList.map(({name}) => name).join(', ')}`);
217
229
  }
218
230
 
231
+ // CAP Generator API
219
232
  async stepEnd() {
220
233
  for (const template of this.templateList) {
221
234
  await template.finalize();
@@ -27,7 +27,7 @@ applications:
27
27
  - {{appName}}-db
28
28
  {{/hasHana}}
29
29
  {{#hasXsuaa}}
30
- - {{appNames}}-auth
30
+ - {{appName}}-auth
31
31
  {{/hasXsuaa}}
32
32
 
33
33
  {{#hasHana}}