@sap/cds-dk 4.9.6 → 6.0.2
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 +68 -0
- package/bin/activate.js +4 -4
- package/bin/add.js +11 -5
- package/bin/bind.js +16 -28
- package/bin/build/all.js +2 -2
- package/bin/build/index.js +12 -19
- package/bin/cds.js +16 -17
- package/bin/compile/index.js +12 -3
- package/bin/deploy/index.js +14 -14
- package/bin/deploy/to-hana.js +4 -4
- package/bin/deploy/to-sqlite.js +1 -1
- package/bin/env.js +13 -4
- package/bin/eval.js +1 -1
- package/bin/fix-redirects.js +1 -1
- package/bin/import.js +44 -179
- package/bin/repl.js +1 -1
- package/bin/watch.js +10 -15
- package/lib/bind/BindingManager.js +87 -0
- package/lib/bind/bindingResolver.js +14 -85
- package/lib/bind/bindingUtil.js +18 -11
- package/lib/bind/cfKeyProvider.js +58 -29
- package/lib/bind/kubernetesCredentialsProvider.js +44 -21
- package/lib/bind/userCdsrcJsonStorageProvider.js +12 -18
- package/lib/cds.js +13 -0
- package/lib/client/base_command.js +3 -2
- package/lib/client/extend.js +6 -7
- package/lib/client/helper/fs_helper.js +7 -8
- package/lib/client/settings_manager.js +14 -10
- package/lib/compile/index.js +9 -10
- package/lib/compile/openapi/csdl2openapi.js +151 -43
- package/lib/compile/openapi/index.js +2 -2
- package/lib/compile/to-xsuaa.js +3 -2
- package/lib/import/common.js +342 -27
- package/lib/import/importapi.js +81 -13
- package/lib/import/message.js +4 -4
- package/lib/import/odata/index.js +141 -0
- package/lib/import/{utils → odata/metadataconverter}/MetadataConverter.js +2 -2
- package/lib/import/{utils → odata/metadataconverter}/MetadataConverterFactory.js +1 -1
- package/lib/import/{utils → odata/util}/MultiMap.js +0 -0
- package/lib/import/{v2parser.js → odata/v2parser.js} +405 -468
- package/lib/import/{v4parser.js → odata/v4parser.js} +311 -322
- package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Aggregation.V1.json +0 -0
- package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Authorization.V1.json +0 -0
- package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Capabilities.V1.json +0 -0
- package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Core.V1.json +0 -0
- package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Measures.V1.json +0 -0
- package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Validation.V1.json +0 -0
- package/lib/import/openapi/importOpenAPI.js +521 -0
- package/lib/import/openapi/index.js +19 -0
- package/lib/import/openapi/utilities.js +38 -0
- package/lib/index.js +1 -1
- package/lib/init/constants.js +7 -2
- package/lib/init/index.js +10 -3
- package/lib/init/template/_merging/existences.js +79 -19
- package/lib/init/template/approuter/files/mta.yaml.hbs +25 -11
- package/lib/init/template/approuter/files/package.json +1 -1
- package/lib/init/template/approuter/files/xs-app.json.hbs +7 -0
- package/lib/init/template/approuter/index.js +61 -54
- package/lib/init/template/auditlog/index.js +2 -2
- package/lib/init/template/data/index.js +2 -2
- package/lib/init/template/hana/files/mta.yaml.hbs +17 -17
- package/lib/init/template/hana/index.js +8 -4
- package/lib/init/template/helm/index.js +39 -0
- package/lib/init/template/helm/update/index.js +28 -0
- package/lib/init/template/java/index.js +7 -9
- package/lib/init/template/kibana-logging/index.js +5 -6
- package/lib/init/template/mta/index.js +4 -4
- package/lib/init/template/mtx/files/java/package.json +9 -9
- package/lib/init/template/mtx/files/mta.yaml.hbs +0 -7
- package/lib/init/template/mtx/files/xs-security.json.hbs +11 -20
- package/lib/init/template/mtx/index.js +50 -57
- package/lib/init/template/nodejs/files/package.json.hbs +2 -2
- package/lib/init/template/notebook/index.js +2 -0
- package/lib/init/template/templateBase.js +6 -4
- package/lib/init/template/xsuaa/index.js +9 -5
- package/lib/init/util/fsUtil.js +25 -10
- package/lib/init/util/logger.js +1 -1
- package/lib/init/util/mvnArchetypeUtil.js +4 -10
- package/lib/init/util/projectReader.js +16 -8
- package/lib/init/util/templateUtil.js +30 -34
- package/lib/k8s/ChartAdder.js +65 -0
- package/lib/k8s/ChartBuilder.js +186 -0
- package/lib/k8s/Context.js +71 -0
- package/lib/k8s/ImageUtil.js +21 -0
- package/lib/k8s/Model.d.ts +53 -0
- package/lib/k8s/auditlog/index.js +29 -0
- package/lib/k8s/auditlog/templates/auditlog.yaml +1 -0
- package/lib/k8s/buildModel.js +70 -0
- package/lib/k8s/connectivity/index.js +74 -0
- package/lib/k8s/connectivity/templates/connectivity-binding.yaml +9 -0
- package/lib/k8s/connectivity/templates/connectivity-proxy-info.yaml +16 -0
- package/lib/k8s/connectivity/templates/connectivity.yaml +1 -0
- package/lib/k8s/deployment/index.js +81 -0
- package/lib/k8s/deployment/subchart/Chart.yaml +6 -0
- package/lib/k8s/deployment/subchart/templates/_helpers.tpl +156 -0
- package/lib/k8s/deployment/subchart/templates/api-rule.yaml +24 -0
- package/lib/k8s/deployment/subchart/templates/deployment.yaml +110 -0
- package/lib/k8s/deployment/subchart/templates/network-policy.yaml +16 -0
- package/lib/k8s/deployment/subchart/templates/pod-disruption-budget.yaml +11 -0
- package/lib/k8s/deployment/subchart/templates/secret.yaml +10 -0
- package/lib/k8s/deployment/subchart/templates/service-binding.yaml +27 -0
- package/lib/k8s/deployment/subchart/templates/service.yaml +11 -0
- package/lib/k8s/deployment/subchart/values-lint.yaml +8 -0
- package/lib/k8s/deployment/subchart/values.schema.json +449 -0
- package/lib/k8s/deployment/subchart/values.yaml +76 -0
- package/lib/k8s/deployment/subchart-override/templates/_web_application_helpers.tpl +81 -0
- package/lib/k8s/destinations/index.js +40 -0
- package/lib/k8s/destinations/lib.js +16 -0
- package/lib/k8s/destinations/templates/destinations.yaml +1 -0
- package/lib/k8s/docker/push.js +8 -0
- package/lib/k8s/event-mesh/index.js +53 -0
- package/lib/k8s/event-mesh/lib.js +9 -0
- package/lib/k8s/event-mesh/templates/event-mesh.yaml +1 -0
- package/lib/k8s/hana-deployer/index.js +38 -0
- package/lib/k8s/hana-deployer/templates/hana-deployer-job.yaml +41 -0
- package/lib/k8s/helm/Release.js +80 -0
- package/lib/k8s/html5-apps-deployer/index.js +43 -0
- package/lib/k8s/html5-apps-deployer/templates/_html5_deployment_helpers.tpl +16 -0
- package/lib/k8s/html5-apps-deployer/templates/html5-apps-deployer-job.yaml +53 -0
- package/lib/k8s/html5-apps-repo-host/index.js +26 -0
- package/lib/k8s/html5-apps-repo-host/lib.js +16 -0
- package/lib/k8s/html5-apps-repo-host/templates/html5-apps-repo-host.yaml +1 -0
- package/lib/k8s/index.js +153 -0
- package/lib/k8s/modules.js +36 -0
- package/lib/k8s/multitenancy/index.js +24 -0
- package/lib/k8s/multitenancy/lib.js +25 -0
- package/lib/k8s/multitenancy/templates/saas-registry.yaml +19 -0
- package/lib/k8s/readProject.js +14 -0
- package/lib/k8s/resources/helm/chart/templates/NOTES.txt +11 -0
- package/lib/k8s/resources/helm/chart/templates/_deployment_helpers.tpl +221 -0
- package/lib/k8s/resources/helm/chart/templates/_helpers.tpl +167 -0
- package/lib/k8s/resources/helm/chart/templates/_sapcp_helpers.tpl +103 -0
- package/lib/k8s/util.js +186 -0
- package/lib/k8s/wrapFeature.js +55 -0
- package/lib/k8s/xsuaa/index.js +64 -0
- package/lib/k8s/xsuaa/lib.js +14 -0
- package/lib/k8s/xsuaa/templates/xsuaa.yaml +1 -0
- package/lib/util/exec.js +1 -1
- package/lib/util/write.js +1 -1
- package/lib/watch/node-watch.js +43 -14
- package/npm-shrinkwrap.json +914 -2745
- package/package.json +5 -5
- package/lib/import/index.js +0 -235
|
@@ -3,72 +3,60 @@
|
|
|
3
3
|
* OData V4 to CSN parser
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
"use strict";
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
let
|
|
9
|
-
let
|
|
10
|
-
let
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
let unboundedActions = {};
|
|
16
|
-
let boundedActions = {};
|
|
17
|
-
let unboundedFunctions = {};
|
|
18
|
-
let boundedFunctions = {};
|
|
19
|
-
let errors = [];
|
|
20
|
-
let Multimap = require('../import/utils/MultiMap.js');
|
|
21
|
-
let entitySetToEntityTypeMap = new Multimap();
|
|
22
|
-
let actionImportToActionMap = new Multimap();
|
|
23
|
-
let functionImportToFunctionMap = new Multimap();
|
|
24
|
-
let validEdmDatatypes = ['Edm.DateTimeOffset'];
|
|
25
|
-
let jsonEntityContainerName;
|
|
26
|
-
let entityTypes = [];
|
|
27
|
-
const ignoreObjects = ['$Reference']; // add all the objects that needs to be ignored for parsing.
|
|
28
|
-
const { warn } = require('@sap/cds/bin/utils/term');
|
|
8
|
+
let messages = require("../message").getMessages();
|
|
9
|
+
let common = require("../common");
|
|
10
|
+
let versionInfo = require("../../../package.json").version;
|
|
11
|
+
let Multimap = require("./util/MultiMap");
|
|
12
|
+
const ignoreObjects = ["$Reference"]; // add all the objects that needs to be ignored for parsing.
|
|
13
|
+
const validEdmDatatypes = ["Edm.DateTimeOffset"];
|
|
14
|
+
const { warn } = require("../../util/term");
|
|
15
|
+
const MetadataConverterFactory = require("./metadataconverter/MetadataConverterFactory");
|
|
29
16
|
|
|
30
|
-
const MetadataConverterFactory = require('../import/utils/MetadataConverterFactory');
|
|
31
17
|
const edmxncdsdatatype = {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
'Edm.SByte': 'cds.Integer',
|
|
45
|
-
'Edm.Double': 'cds.Double',
|
|
18
|
+
"Edm.String": "cds.LargeString",
|
|
19
|
+
"Edm.Boolean": "cds.Boolean",
|
|
20
|
+
"Edm.Int16": "cds.Integer",
|
|
21
|
+
"Edm.Int32": "cds.Integer",
|
|
22
|
+
"Edm.Int64": "cds.Integer64",
|
|
23
|
+
"Edm.Decimal": "cds.Decimal",
|
|
24
|
+
"Edm.DateTimeOffset": "cds.DateTime",
|
|
25
|
+
"Edm.TimeOfDay": "cds.Time",
|
|
26
|
+
"Edm.Date": "cds.Date",
|
|
27
|
+
"Edm.Binary": "cds.LargeBinary",
|
|
28
|
+
"Edm.Guid": "cds.UUID",
|
|
29
|
+
"Edm.Double": "cds.Double",
|
|
46
30
|
// Special handling of data types
|
|
47
|
-
|
|
48
|
-
|
|
31
|
+
"Edm.String_m": "cds.String", // Max length
|
|
32
|
+
"Edm.Decimal_p": "cds.Decimal", // Precision, scale
|
|
49
33
|
//'Edm.DateTime_f': 'cds.Date', // sap:display-format="Date"
|
|
50
34
|
//'Edm.DateTimeOffset_f': 'cds.Date', // sap:display-format="Date"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
35
|
+
"Edm.Binary_m": "cds.Binary", // Max Length
|
|
36
|
+
"Edm.Byte_m": "cds.Integer", // Max Length
|
|
37
|
+
"Edm.Double_p": "cds.Double", // Precision, scale
|
|
54
38
|
// Special handling with annotations
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
39
|
+
"Edm.Byte_a": "cds.Integer",
|
|
40
|
+
"Edm.SByte_a": "cds.Integer",
|
|
41
|
+
"Edm.Single_a": "cds.Double",
|
|
42
|
+
"Edm.Stream_a": "cds.LargeBinary",
|
|
43
|
+
"Edm.DateTimeOffset_a": "cds.Timestamp",
|
|
58
44
|
};
|
|
59
45
|
|
|
60
|
-
function _initialize() {
|
|
61
|
-
unboundedActions = {};
|
|
62
|
-
boundedActions = {};
|
|
63
|
-
unboundedFunctions = {};
|
|
64
|
-
boundedFunctions = {};
|
|
65
|
-
entityTypes = [];
|
|
66
|
-
namespace = "";
|
|
67
|
-
complexTypes = {};
|
|
68
|
-
enumTypes = {};
|
|
69
|
-
typeDefinitions = {};
|
|
70
|
-
jsonEntityContainerName = "";
|
|
71
|
-
|
|
46
|
+
function _initialize(parserContext) {
|
|
47
|
+
parserContext.unboundedActions = {};
|
|
48
|
+
parserContext.boundedActions = {};
|
|
49
|
+
parserContext.unboundedFunctions = {};
|
|
50
|
+
parserContext.boundedFunctions = {};
|
|
51
|
+
parserContext.entityTypes = [];
|
|
52
|
+
parserContext.namespace = "";
|
|
53
|
+
parserContext.complexTypes = {};
|
|
54
|
+
parserContext.enumTypes = {};
|
|
55
|
+
parserContext.typeDefinitions = {};
|
|
56
|
+
parserContext.jsonEntityContainerName = "";
|
|
57
|
+
parserContext.entitySetToEntityTypeMap = new Multimap();
|
|
58
|
+
parserContext.actionImportToActionMap = new Multimap();
|
|
59
|
+
parserContext.functionImportToFunctionMap = new Multimap();
|
|
72
60
|
}
|
|
73
61
|
|
|
74
62
|
function _isJson(edmx) {
|
|
@@ -89,12 +77,12 @@ function _isValidDataType(propertyType) {
|
|
|
89
77
|
return false;
|
|
90
78
|
}
|
|
91
79
|
|
|
92
|
-
function _isValidJSON(jsonObj) {
|
|
80
|
+
function _isValidJSON(jsonObj, parserContext) {
|
|
93
81
|
let tempNamespace = jsonObj.$EntityContainer;
|
|
94
|
-
namespace = tempNamespace.substring(0, tempNamespace.lastIndexOf('.'));
|
|
95
|
-
jsonEntityContainerName = tempNamespace.substring(tempNamespace.lastIndexOf('.') + 1);
|
|
82
|
+
parserContext.namespace = tempNamespace.substring(0, tempNamespace.lastIndexOf('.'));
|
|
83
|
+
parserContext.jsonEntityContainerName = tempNamespace.substring(tempNamespace.lastIndexOf('.') + 1);
|
|
96
84
|
|
|
97
|
-
if (jsonObj.$Version && jsonObj.$EntityContainer && jsonObj[namespace]) {
|
|
85
|
+
if (jsonObj.$Version && jsonObj.$EntityContainer && jsonObj[parserContext.namespace]) {
|
|
98
86
|
return true;
|
|
99
87
|
}
|
|
100
88
|
else {
|
|
@@ -102,40 +90,24 @@ function _isValidJSON(jsonObj) {
|
|
|
102
90
|
}
|
|
103
91
|
}
|
|
104
92
|
|
|
105
|
-
function _hasEntityContainer(jsonObj) {
|
|
106
|
-
if (jsonObj[namespace][jsonEntityContainerName] &&
|
|
93
|
+
function _hasEntityContainer(jsonObj, parserContext) {
|
|
94
|
+
if (jsonObj[parserContext.namespace][parserContext.jsonEntityContainerName] &&
|
|
95
|
+
jsonObj[parserContext.namespace][parserContext.jsonEntityContainerName] instanceof Object
|
|
96
|
+
) {
|
|
107
97
|
return true;
|
|
108
98
|
} else {
|
|
109
99
|
throw new Error(messages.MISSING_ENTITY_CONTAINER);
|
|
110
100
|
}
|
|
111
101
|
}
|
|
112
102
|
|
|
113
|
-
function
|
|
114
|
-
let entitySetCount = 0;
|
|
115
|
-
let entityContainerData = jsonObj[namespace][jsonEntityContainerName];
|
|
116
|
-
Object.keys(entityContainerData).forEach(data => {
|
|
117
|
-
if (ignoreObjects.indexOf(data) === -1 && entityContainerData[data] instanceof Object) {
|
|
118
|
-
if (entityContainerData[data].$Collection === true) {
|
|
119
|
-
entitySetCount += 1;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
if (entitySetCount == 0) {
|
|
125
|
-
throw new Error(messages.MISSING_ENTITY_SETS);
|
|
126
|
-
}
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function _validateJSON(jsonObj) {
|
|
103
|
+
function _validateJSON(jsonObj, parserContext) {
|
|
131
104
|
return (
|
|
132
|
-
_isValidJSON(jsonObj) &&
|
|
133
|
-
_hasEntityContainer(jsonObj)
|
|
134
|
-
_hasEntitySet(jsonObj)
|
|
105
|
+
_isValidJSON(jsonObj, parserContext) &&
|
|
106
|
+
_hasEntityContainer(jsonObj, parserContext)
|
|
135
107
|
);
|
|
136
108
|
}
|
|
137
109
|
|
|
138
|
-
function _includeExternalNamespaceAnnotation(source,target){
|
|
110
|
+
function _includeExternalNamespaceAnnotation(source, target) {
|
|
139
111
|
Object.entries(source).forEach(element => {
|
|
140
112
|
if (element[0].startsWith('@')) {
|
|
141
113
|
target[element[0]] = element[1];
|
|
@@ -144,11 +116,11 @@ function _includeExternalNamespaceAnnotation(source,target){
|
|
|
144
116
|
}
|
|
145
117
|
|
|
146
118
|
function _typeWithCollections(property, type, isCollection) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
119
|
+
if (isCollection === true) {
|
|
120
|
+
property.items = type;
|
|
121
|
+
} else {
|
|
122
|
+
Object.assign(property, type);
|
|
123
|
+
}
|
|
152
124
|
}
|
|
153
125
|
|
|
154
126
|
function generatePropertyCsn(propertyType, isPrimaryKey) {
|
|
@@ -160,7 +132,7 @@ function generatePropertyCsn(propertyType, isPrimaryKey) {
|
|
|
160
132
|
if (propertyType.$Collection)
|
|
161
133
|
throw new Error(messages.COLLECTION_IN_KEY);
|
|
162
134
|
}
|
|
163
|
-
_includeExternalNamespaceAnnotation(propertyType,property);
|
|
135
|
+
_includeExternalNamespaceAnnotation(propertyType, property);
|
|
164
136
|
// conditions have to be made
|
|
165
137
|
if (propertyType.$MaxLength) {
|
|
166
138
|
if (propertyType.$Type) {
|
|
@@ -169,34 +141,35 @@ function generatePropertyCsn(propertyType, isPrimaryKey) {
|
|
|
169
141
|
typeProperties.type = 'cds.String'; // if type is missing, then it is String type
|
|
170
142
|
}
|
|
171
143
|
typeProperties.length = propertyType.$MaxLength;
|
|
172
|
-
} else if(_isValidDataType(propertyType.$Type)) {
|
|
173
|
-
if(propertyType.$Precision && propertyType.$Precision > 0)
|
|
174
|
-
{
|
|
144
|
+
} else if (_isValidDataType(propertyType.$Type)) {
|
|
145
|
+
if (propertyType.$Precision && propertyType.$Precision > 0) {
|
|
175
146
|
typeProperties.type = edmxncdsdatatype[propertyType.$Type + '_a'];
|
|
176
|
-
typeProperties["@odata.
|
|
147
|
+
typeProperties["@odata.Precision"] = propertyType.$Precision;
|
|
177
148
|
} else {
|
|
178
149
|
typeProperties.type = edmxncdsdatatype[propertyType.$Type];
|
|
179
|
-
typeProperties["@odata.
|
|
150
|
+
typeProperties["@odata.Precision"] = 0;
|
|
180
151
|
}
|
|
181
152
|
} else if (propertyType.$Precision && !_isValidDataType(propertyType.$Type)) {
|
|
182
153
|
typeProperties.type = edmxncdsdatatype[propertyType.$Type + '_p'];
|
|
183
|
-
|
|
184
|
-
if (propertyType.$Scale && propertyType.$Scale == 'variable') {
|
|
185
|
-
typeProperties.scale = propertyType.$Precision;
|
|
186
|
-
typeProperties.precision = propertyType.$Precision * 2;
|
|
187
|
-
} else {
|
|
154
|
+
if (propertyType.$Scale && !(propertyType.$Scale == 'variable' || propertyType.$Scale == 'floating')) {
|
|
188
155
|
typeProperties.scale = propertyType.$Scale;
|
|
156
|
+
typeProperties.precision = propertyType.$Precision;
|
|
189
157
|
}
|
|
190
158
|
} else if (edmxncdsdatatype[propertyType.$Type + "_a"]) {
|
|
191
159
|
typeProperties.type = edmxncdsdatatype[propertyType.$Type + "_a"];
|
|
192
160
|
} else if (propertyType.$Type) {
|
|
193
161
|
typeProperties.type = edmxncdsdatatype[propertyType.$Type];
|
|
194
|
-
} else{
|
|
162
|
+
} else {
|
|
195
163
|
typeProperties.type = 'cds.LargeString'; // if type is missing, then it is String type
|
|
196
164
|
}
|
|
197
165
|
|
|
198
166
|
if (edmxncdsdatatype[propertyType.$Type + '_a']) {
|
|
199
|
-
|
|
167
|
+
if (edmxncdsdatatype[propertyType.$Type + '_a'] === 'cds.LargeBinary') {
|
|
168
|
+
typeProperties["@Core.MediaType"] = 'application/octet-stream';
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
typeProperties["@odata.Type"] = propertyType.$Type;
|
|
172
|
+
}
|
|
200
173
|
}
|
|
201
174
|
|
|
202
175
|
_typeWithCollections(property, typeProperties, propertyType.$Collection);
|
|
@@ -206,23 +179,23 @@ function generatePropertyCsn(propertyType, isPrimaryKey) {
|
|
|
206
179
|
|
|
207
180
|
function _generateComplexTypePropertyCsn(propertyType) {
|
|
208
181
|
let property = {};
|
|
209
|
-
let type = {type
|
|
182
|
+
let type = { type: propertyType.$Type }
|
|
210
183
|
_typeWithCollections(property, type, propertyType.$Collection);
|
|
211
|
-
|
|
184
|
+
|
|
212
185
|
return property;
|
|
213
186
|
}
|
|
214
187
|
|
|
215
188
|
function _generateTypeDefinitionPropertyCsn(propertyType) {
|
|
216
189
|
let property = {};
|
|
217
|
-
let type = {type
|
|
218
|
-
|
|
219
|
-
_includeExternalNamespaceAnnotation(propertyType,property);
|
|
190
|
+
let type = { type: propertyType.$Type }
|
|
191
|
+
|
|
192
|
+
_includeExternalNamespaceAnnotation(propertyType, property);
|
|
220
193
|
_typeWithCollections(property, type, propertyType.$Collection);
|
|
221
194
|
|
|
222
195
|
return property;
|
|
223
196
|
}
|
|
224
197
|
|
|
225
|
-
function _parseAssociationProperty(foreignReference, associationNode, mockServerUc) {
|
|
198
|
+
function _parseAssociationProperty(foreignReference, associationNode, mockServerUc, parserContext) {
|
|
226
199
|
let associationProperty = {};
|
|
227
200
|
let foreignKeys;
|
|
228
201
|
// var foreignReference = associationNode.$Type;
|
|
@@ -230,20 +203,20 @@ function _parseAssociationProperty(foreignReference, associationNode, mockServer
|
|
|
230
203
|
let i;
|
|
231
204
|
let data;
|
|
232
205
|
let ref;
|
|
233
|
-
associationProperty.type = 'cds.Association';
|
|
206
|
+
associationProperty.type = (associationNode.$OnDelete === 'Cascade') ? 'cds.Composition' : 'cds.Association';
|
|
234
207
|
// annotation for ON condition
|
|
235
208
|
associationProperty["@cds.ambiguous"] = 'missing on condition?';
|
|
236
209
|
// associationProperty.target = associationNode.$Type;
|
|
237
|
-
if (mockServerUc && entitySetToEntityTypeMap && entitySetToEntityTypeMap.get(associationNode.$Type)) {
|
|
238
|
-
if (entitySetToEntityTypeMap.get(associationNode.$Type).length > 1) {
|
|
239
|
-
for (let j = 0; j < entitySetToEntityTypeMap.get(associationNode.$Type).length; j++) {
|
|
240
|
-
if (entitySetToEntityTypeMap.get(associationNode.$Type)[j] === foreignReference) {
|
|
241
|
-
associationProperty.target = namespace + '.' +
|
|
242
|
-
|
|
210
|
+
if (mockServerUc && parserContext.entitySetToEntityTypeMap && parserContext.entitySetToEntityTypeMap.get(associationNode.$Type)) {
|
|
211
|
+
if (parserContext.entitySetToEntityTypeMap.get(associationNode.$Type).length > 1) {
|
|
212
|
+
for (let j = 0; j < parserContext.entitySetToEntityTypeMap.get(associationNode.$Type).length; j++) {
|
|
213
|
+
if (parserContext.entitySetToEntityTypeMap.get(associationNode.$Type)[j] === foreignReference) {
|
|
214
|
+
associationProperty.target = parserContext.namespace + '.' +
|
|
215
|
+
parserContext.entitySetToEntityTypeMap.get(associationNode.$Type)[j];
|
|
243
216
|
}
|
|
244
217
|
}
|
|
245
218
|
} else {
|
|
246
|
-
associationProperty.target = namespace + '.' + entitySetToEntityTypeMap.get(associationNode.$Type);
|
|
219
|
+
associationProperty.target = parserContext.namespace + '.' + parserContext.entitySetToEntityTypeMap.get(associationNode.$Type);
|
|
247
220
|
}
|
|
248
221
|
} else {
|
|
249
222
|
associationProperty.target = associationNode.$Type;
|
|
@@ -277,49 +250,58 @@ function _parseAssociationProperty(foreignReference, associationNode, mockServer
|
|
|
277
250
|
}
|
|
278
251
|
}
|
|
279
252
|
}
|
|
280
|
-
|
|
253
|
+
// Convert managed associations and compositions in unmanaged with empty key to avoid
|
|
281
254
|
// "generation" of keys, that do not exist in the external service.
|
|
282
255
|
if (common.checkForEmptyKeys(associationProperty, "V4")) {
|
|
283
256
|
associationProperty.keys = [];
|
|
284
257
|
}
|
|
285
|
-
_includeExternalNamespaceAnnotation(associationNode,associationProperty);
|
|
258
|
+
_includeExternalNamespaceAnnotation(associationNode, associationProperty);
|
|
286
259
|
return associationProperty;
|
|
287
260
|
}
|
|
288
261
|
|
|
289
|
-
function _getBaseTypeEntityName(baseType) {
|
|
290
|
-
const mappedResult = entitySetToEntityTypeMap.get(baseType);
|
|
262
|
+
function _getBaseTypeEntityName(baseType, parserContext) {
|
|
263
|
+
const mappedResult = parserContext.entitySetToEntityTypeMap.get(baseType);
|
|
291
264
|
// if one entity type has mapping to multiple entity sets, use the first entity set
|
|
292
265
|
if (mappedResult.length > 1) {
|
|
293
|
-
return namespace + '.' + mappedResult[0];
|
|
266
|
+
return parserContext.namespace + '.' + mappedResult[0];
|
|
294
267
|
} else {
|
|
295
|
-
return namespace + '.' + mappedResult;
|
|
268
|
+
return parserContext.namespace + '.' + mappedResult;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function _addBlobElement() {
|
|
273
|
+
return {
|
|
274
|
+
"blob": {
|
|
275
|
+
"@Core.MediaType": 'application/octet-stream',
|
|
276
|
+
"type": "cds.LargeBinary"
|
|
277
|
+
}
|
|
296
278
|
}
|
|
297
279
|
}
|
|
298
280
|
|
|
299
|
-
function _generateCSNForEntityType(ignorePersistenceSkip, mockServerUc) {
|
|
281
|
+
function _generateCSNForEntityType(ignorePersistenceSkip, mockServerUc, parserContext) {
|
|
300
282
|
let entityCsn = {};
|
|
301
283
|
let keySet;
|
|
302
284
|
let curKey;
|
|
303
285
|
let j;
|
|
304
286
|
let propertyType;
|
|
305
287
|
let enumType = {};
|
|
306
|
-
entityTypes.forEach(element => {
|
|
288
|
+
parserContext.entityTypes.forEach(element => {
|
|
307
289
|
let key = Object.keys(element)[0];
|
|
308
290
|
let baseType = element[key].$BaseType;
|
|
309
291
|
let isAbstract = element[key].$Abstract;
|
|
310
292
|
if (key) {
|
|
311
293
|
entityCsn[key] = {};
|
|
312
294
|
entityCsn[key].kind = 'entity';
|
|
313
|
-
if (!ignorePersistenceSkip) {
|
|
314
|
-
entityCsn[key]['@cds.persistence.skip'] = true;
|
|
295
|
+
if (!ignorePersistenceSkip) {
|
|
296
|
+
entityCsn[key]['@cds.persistence.skip'] = true;
|
|
315
297
|
}
|
|
316
|
-
_includeExternalNamespaceAnnotation(element[key],entityCsn[key]);
|
|
298
|
+
_includeExternalNamespaceAnnotation(element[key], entityCsn[key]);
|
|
317
299
|
// inheritance
|
|
318
300
|
if (baseType) {
|
|
319
301
|
entityCsn[key].includes = [];
|
|
320
302
|
// if the baseType has a mapping to an entity set use that
|
|
321
|
-
if (entitySetToEntityTypeMap && entitySetToEntityTypeMap.get(baseType)) {
|
|
322
|
-
baseType = _getBaseTypeEntityName(baseType);
|
|
303
|
+
if (parserContext.entitySetToEntityTypeMap && parserContext.entitySetToEntityTypeMap.get(baseType)) {
|
|
304
|
+
baseType = _getBaseTypeEntityName(baseType, parserContext);
|
|
323
305
|
}
|
|
324
306
|
entityCsn[key].includes.push(baseType);
|
|
325
307
|
}
|
|
@@ -338,43 +320,47 @@ function _generateCSNForEntityType(ignorePersistenceSkip, mockServerUc) {
|
|
|
338
320
|
for (j = 0; j < curKey.length; j++) {
|
|
339
321
|
keySet.push(curKey[j]);
|
|
340
322
|
}
|
|
341
|
-
} else if (!element[key][property].$Type || edmxncdsdatatype[element[key][property].$Type] ||
|
|
323
|
+
} else if (!element[key][property].$Type || edmxncdsdatatype[element[key][property].$Type] ||
|
|
324
|
+
edmxncdsdatatype[element[key][property].$Type + "_a"]
|
|
325
|
+
) {
|
|
342
326
|
propertyType = element[key][property];
|
|
343
327
|
if (keySet.includes(property)) {
|
|
344
328
|
entityCsn[key].elements[property] = generatePropertyCsn(propertyType, true);
|
|
345
329
|
} else {
|
|
346
330
|
entityCsn[key].elements[property] = generatePropertyCsn(propertyType, false);
|
|
347
331
|
}
|
|
348
|
-
} else if (!element[key][property].$Type || enumTypes[element[key][property].$Type]) {
|
|
349
|
-
enumType.$Type = enumTypes[element[key][property].$Type].$UnderlyingType;
|
|
332
|
+
} else if (!element[key][property].$Type || parserContext.enumTypes[element[key][property].$Type]) {
|
|
333
|
+
enumType.$Type = parserContext.enumTypes[element[key][property].$Type].$UnderlyingType;
|
|
350
334
|
if (keySet.includes(property)) {
|
|
351
335
|
entityCsn[key].elements[property] = generatePropertyCsn(enumType, true);
|
|
352
336
|
} else {
|
|
353
337
|
entityCsn[key].elements[property] = generatePropertyCsn(enumType, false);
|
|
354
338
|
}
|
|
355
|
-
} else if (complexTypes[element[key][property].$Type]) {
|
|
339
|
+
} else if (parserContext.complexTypes[element[key][property].$Type]) {
|
|
356
340
|
propertyType = element[key][property];
|
|
357
341
|
entityCsn[key].elements[property] = _generateComplexTypePropertyCsn(propertyType);
|
|
358
342
|
} else if (element[key][property].$Kind === 'NavigationProperty') {
|
|
359
|
-
entityCsn[key].elements[property] = _parseAssociationProperty(property,
|
|
360
|
-
|
|
361
|
-
} else if (typeDefinitions[element[key][property].$Type]){
|
|
343
|
+
entityCsn[key].elements[property] = _parseAssociationProperty(property, element[key][property], mockServerUc, parserContext);
|
|
344
|
+
} else if (parserContext.typeDefinitions[element[key][property].$Type]) {
|
|
362
345
|
// for TypeDefinitions
|
|
363
346
|
propertyType = element[key][property];
|
|
364
347
|
entityCsn[key].elements[property] = _generateTypeDefinitionPropertyCsn(propertyType);
|
|
365
348
|
} else {
|
|
366
|
-
let message = '"' + element[key][property].$Type + '" is not supported (in element:"' + property + '")';
|
|
349
|
+
let message = '"' + element[key][property].$Type + '" is not supported (in element:"' + property + '")';
|
|
367
350
|
console.log(warn(message));
|
|
368
351
|
}
|
|
369
352
|
}
|
|
370
353
|
}
|
|
371
354
|
});
|
|
355
|
+
if (element[key].$HasStream) {
|
|
356
|
+
entityCsn[key].elements = { ...entityCsn[key].elements, ..._addBlobElement() }
|
|
357
|
+
}
|
|
372
358
|
}
|
|
373
359
|
});
|
|
374
360
|
return entityCsn;
|
|
375
361
|
}
|
|
376
362
|
|
|
377
|
-
function _generateEntityType(schemaData, mockServerUc) {
|
|
363
|
+
function _generateEntityType(schemaData, mockServerUc, parserContext) {
|
|
378
364
|
let entity = {};
|
|
379
365
|
let temp;
|
|
380
366
|
Object.keys(schemaData).forEach(entityType => {
|
|
@@ -382,64 +368,66 @@ function _generateEntityType(schemaData, mockServerUc) {
|
|
|
382
368
|
if (schemaData[entityType] instanceof Object) {
|
|
383
369
|
if (schemaData[entityType].$Kind && schemaData[entityType].$Kind === 'EntityType') {
|
|
384
370
|
if (mockServerUc) {
|
|
385
|
-
let entityTypeName = namespace + '.' + entityType;
|
|
386
|
-
if (entitySetToEntityTypeMap && entitySetToEntityTypeMap.get(entityTypeName)) {
|
|
387
|
-
if (entitySetToEntityTypeMap.get(entityTypeName).length > 1) {
|
|
371
|
+
let entityTypeName = parserContext.namespace + '.' + entityType;
|
|
372
|
+
if (parserContext.entitySetToEntityTypeMap && parserContext.entitySetToEntityTypeMap.get(entityTypeName)) {
|
|
373
|
+
if (parserContext.entitySetToEntityTypeMap.get(entityTypeName).length > 1) {
|
|
388
374
|
let entity1 = {};
|
|
389
|
-
for (let i = 0; i < entitySetToEntityTypeMap.get(entityTypeName).length; i++) {
|
|
375
|
+
for (let i = 0; i < parserContext.entitySetToEntityTypeMap.get(entityTypeName).length; i++) {
|
|
390
376
|
entity1 = {};
|
|
391
|
-
let temp1 = namespace + '.' + entitySetToEntityTypeMap.get(entityTypeName)[i];
|
|
377
|
+
let temp1 = parserContext.namespace + '.' + parserContext.entitySetToEntityTypeMap.get(entityTypeName)[i];
|
|
392
378
|
entity1[temp1] = schemaData[entityType];
|
|
393
|
-
entityTypes.push(entity1);
|
|
379
|
+
parserContext.entityTypes.push(entity1);
|
|
394
380
|
}
|
|
395
381
|
} else {
|
|
396
|
-
temp = namespace + '.' + entitySetToEntityTypeMap.get(entityTypeName);
|
|
382
|
+
temp = parserContext.namespace + '.' + parserContext.entitySetToEntityTypeMap.get(entityTypeName);
|
|
397
383
|
entity[temp] = schemaData[entityType];
|
|
398
|
-
entityTypes.push(entity);
|
|
384
|
+
parserContext.entityTypes.push(entity);
|
|
399
385
|
}
|
|
400
386
|
} else {
|
|
401
|
-
temp = namespace + '.' + entityType;
|
|
387
|
+
temp = parserContext.namespace + '.' + entityType;
|
|
402
388
|
entity[temp] = schemaData[entityType];
|
|
403
|
-
entityTypes.push(entity);
|
|
389
|
+
parserContext.entityTypes.push(entity);
|
|
404
390
|
}
|
|
405
391
|
} else {
|
|
406
|
-
temp = namespace + '.' + entityType;
|
|
392
|
+
temp = parserContext.namespace + '.' + entityType;
|
|
407
393
|
entity[temp] = schemaData[entityType];
|
|
408
|
-
entityTypes.push(entity);
|
|
394
|
+
parserContext.entityTypes.push(entity);
|
|
409
395
|
}
|
|
410
396
|
}
|
|
411
397
|
}
|
|
412
398
|
});
|
|
413
399
|
}
|
|
414
400
|
|
|
415
|
-
function _parseEntityType(schemaDataList, ignorePersistenceSkip, mockServerUc) {
|
|
401
|
+
function _parseEntityType(schemaDataList, ignorePersistenceSkip, mockServerUc, parserContext) {
|
|
416
402
|
// collect entity types
|
|
417
403
|
let schemaData;
|
|
418
404
|
for (let i = 0; i < schemaDataList.length; i++) {
|
|
419
405
|
schemaData = schemaDataList[i];
|
|
420
|
-
_generateEntityType(schemaData, mockServerUc);
|
|
406
|
+
_generateEntityType(schemaData, mockServerUc, parserContext);
|
|
421
407
|
}
|
|
422
|
-
return _generateCSNForEntityType(ignorePersistenceSkip, mockServerUc);
|
|
408
|
+
return _generateCSNForEntityType(ignorePersistenceSkip, mockServerUc, parserContext);
|
|
423
409
|
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
410
|
+
|
|
411
|
+
function _parseEntityContainer(entityCSN, schemaData, parserContext) {
|
|
412
|
+
Object.entries(schemaData[0][parserContext.jsonEntityContainerName]).forEach(entry => {
|
|
413
|
+
if (entityCSN[parserContext.namespace + '.' + entry[0]])
|
|
427
414
|
//Captured the annotations at entity set and entity type name level
|
|
428
|
-
_includeExternalNamespaceAnnotation(entry[1],entityCSN[namespace + '.' + entry[0]]);
|
|
429
|
-
if(entry[0].startsWith('@')){
|
|
415
|
+
_includeExternalNamespaceAnnotation(entry[1], entityCSN[parserContext.namespace + '.' + entry[0]]);
|
|
416
|
+
if (entry[0].startsWith('@')) {
|
|
430
417
|
//Captured the annotations at entity container name level
|
|
431
|
-
entityCSN[namespace][entry[0]]= entry[1];
|
|
418
|
+
entityCSN[parserContext.namespace][entry[0]] = entry[1];
|
|
432
419
|
}
|
|
433
420
|
});
|
|
434
421
|
return entityCSN;
|
|
435
422
|
}
|
|
436
|
-
|
|
423
|
+
|
|
424
|
+
function _generateEnumType(schemaData, parserContext) {
|
|
437
425
|
let enumTypeDict = {};
|
|
438
426
|
let temp;
|
|
439
427
|
Object.keys(schemaData).forEach(curEnumType => {
|
|
440
428
|
if (schemaData[curEnumType] instanceof Object) {
|
|
441
429
|
if (schemaData[curEnumType].$Kind && schemaData[curEnumType].$Kind === 'EnumType') {
|
|
442
|
-
temp = namespace + '.' + curEnumType;
|
|
430
|
+
temp = parserContext.namespace + '.' + curEnumType;
|
|
443
431
|
enumTypeDict[temp] = schemaData[curEnumType];
|
|
444
432
|
}
|
|
445
433
|
}
|
|
@@ -447,22 +435,21 @@ function _generateEnumType(schemaData) {
|
|
|
447
435
|
return enumTypeDict;
|
|
448
436
|
}
|
|
449
437
|
|
|
450
|
-
function _collectEnumType(schemaDataList) {
|
|
438
|
+
function _collectEnumType(schemaDataList, parserContext) {
|
|
451
439
|
let schemaData;
|
|
452
440
|
for (let i = 0; i < schemaDataList.length; i++) {
|
|
453
441
|
schemaData = schemaDataList[i];
|
|
454
|
-
enumTypes = _generateEnumType(schemaData);
|
|
442
|
+
parserContext.enumTypes = _generateEnumType(schemaData, parserContext);
|
|
455
443
|
}
|
|
456
|
-
return enumTypes;
|
|
457
444
|
}
|
|
458
445
|
|
|
459
|
-
function _generateTypeDefinition(schemaData) {
|
|
446
|
+
function _generateTypeDefinition(schemaData, parserContext) {
|
|
460
447
|
let typeDefDict = {};
|
|
461
448
|
let temp;
|
|
462
449
|
Object.keys(schemaData).forEach(curTypeDef => {
|
|
463
450
|
if (schemaData[curTypeDef] instanceof Object) {
|
|
464
451
|
if (schemaData[curTypeDef].$Kind && schemaData[curTypeDef].$Kind === 'TypeDefinition') {
|
|
465
|
-
temp = namespace + '.' + curTypeDef;
|
|
452
|
+
temp = parserContext.namespace + '.' + curTypeDef;
|
|
466
453
|
typeDefDict[temp] = schemaData[curTypeDef];
|
|
467
454
|
}
|
|
468
455
|
}
|
|
@@ -470,29 +457,32 @@ function _generateTypeDefinition(schemaData) {
|
|
|
470
457
|
return typeDefDict;
|
|
471
458
|
}
|
|
472
459
|
|
|
473
|
-
function _collectTypeDefinition(schemaDataList) {
|
|
460
|
+
function _collectTypeDefinition(schemaDataList, parserContext) {
|
|
474
461
|
let schemaData;
|
|
475
462
|
for (let i = 0; i < schemaDataList.length; i++) {
|
|
476
463
|
schemaData = schemaDataList[i];
|
|
477
|
-
typeDefinitions = _generateTypeDefinition(schemaData);
|
|
464
|
+
parserContext.typeDefinitions = _generateTypeDefinition(schemaData, parserContext);
|
|
478
465
|
}
|
|
479
466
|
}
|
|
480
467
|
|
|
481
|
-
function _generateBounded(schemaData, flag) {
|
|
468
|
+
function _generateBounded(schemaData, flag, parserContext) {
|
|
482
469
|
let bFunction = {};
|
|
483
470
|
let boundedFunction = [];
|
|
484
471
|
let temp;
|
|
485
472
|
let kindString;
|
|
486
473
|
if (flag == 1) {
|
|
487
|
-
kindString = 'Function';
|
|
474
|
+
kindString = 'Function';
|
|
488
475
|
}
|
|
489
476
|
else {
|
|
490
477
|
kindString = 'Action';
|
|
491
478
|
}
|
|
492
479
|
Object.keys(schemaData).forEach(curFunction => {
|
|
493
|
-
if (schemaData[curFunction] instanceof Array &&
|
|
480
|
+
if (schemaData[curFunction] instanceof Array &&
|
|
481
|
+
schemaData[curFunction][0].$Kind === kindString &&
|
|
482
|
+
schemaData[curFunction][0].$IsBound === true
|
|
483
|
+
) {
|
|
494
484
|
boundedFunction = [];
|
|
495
|
-
temp = namespace + '.' + curFunction;
|
|
485
|
+
temp = parserContext.namespace + '.' + curFunction;
|
|
496
486
|
for (let i = 0; i < schemaData[curFunction].length; i++) {
|
|
497
487
|
boundedFunction.push(schemaData[curFunction][i]);
|
|
498
488
|
bFunction[temp] = boundedFunction;
|
|
@@ -502,37 +492,37 @@ function _generateBounded(schemaData, flag) {
|
|
|
502
492
|
return bFunction;
|
|
503
493
|
}
|
|
504
494
|
|
|
505
|
-
function _collectBounded(schemaDataList, flag) {
|
|
495
|
+
function _collectBounded(schemaDataList, flag, parserContext) {
|
|
506
496
|
let schemaData;
|
|
507
497
|
for (let i = 0; i < schemaDataList.length; i++) {
|
|
508
498
|
schemaData = schemaDataList[i];
|
|
509
499
|
if (flag == 0) {
|
|
510
|
-
boundedActions = _generateBounded(schemaData, 0);
|
|
500
|
+
parserContext.boundedActions = _generateBounded(schemaData, 0, parserContext);
|
|
511
501
|
}
|
|
512
502
|
else {
|
|
513
|
-
boundedFunctions = _generateBounded(schemaData, 1);
|
|
514
|
-
}
|
|
503
|
+
parserContext.boundedFunctions = _generateBounded(schemaData, 1, parserContext);
|
|
504
|
+
}
|
|
515
505
|
}
|
|
516
506
|
}
|
|
517
507
|
|
|
518
|
-
function _getDatatype(datatype) {
|
|
508
|
+
function _getDatatype(datatype, parserContext) {
|
|
519
509
|
let type = undefined;
|
|
520
510
|
if (datatype === undefined) {
|
|
521
511
|
type = "cds.LargeString"; //intentionally used LargeString
|
|
522
|
-
} else if (entitySetToEntityTypeMap.get(datatype) && entitySetToEntityTypeMap.get(datatype)[0]) {
|
|
512
|
+
} else if (parserContext.entitySetToEntityTypeMap.get(datatype) && parserContext.entitySetToEntityTypeMap.get(datatype)[0]) {
|
|
523
513
|
//mapping to entity set if type is entity type
|
|
524
|
-
type = namespace + "." + entitySetToEntityTypeMap.get(datatype)[0];
|
|
525
|
-
} else if (complexTypes[datatype] || typeDefinitions[datatype] || enumTypes[datatype]) {
|
|
514
|
+
type = parserContext.namespace + "." + parserContext.entitySetToEntityTypeMap.get(datatype)[0];
|
|
515
|
+
} else if (parserContext.complexTypes[datatype] || parserContext.typeDefinitions[datatype] || parserContext.enumTypes[datatype]) {
|
|
526
516
|
//if type is complex type, type definition or an enum type
|
|
527
517
|
type = datatype;
|
|
528
518
|
} else {
|
|
529
519
|
//checking if type is an entity set
|
|
530
|
-
for (const element of entitySetToEntityTypeMap.keys()) {
|
|
531
|
-
if (namespace + "." + entitySetToEntityTypeMap.get(element) === datatype)
|
|
520
|
+
for (const element of parserContext.entitySetToEntityTypeMap.keys()) {
|
|
521
|
+
if (parserContext.namespace + "." + parserContext.entitySetToEntityTypeMap.get(element) === datatype)
|
|
532
522
|
type = datatype;
|
|
533
523
|
}
|
|
534
|
-
entityTypes.forEach(entity =>{
|
|
535
|
-
if(entity[datatype])
|
|
524
|
+
parserContext.entityTypes.forEach(entity => {
|
|
525
|
+
if (entity[datatype])
|
|
536
526
|
type = datatype;
|
|
537
527
|
})
|
|
538
528
|
}
|
|
@@ -541,17 +531,17 @@ function _getDatatype(datatype) {
|
|
|
541
531
|
return type;
|
|
542
532
|
}
|
|
543
533
|
|
|
544
|
-
function _parseBounded(csnDefs, flag) {
|
|
534
|
+
function _parseBounded(csnDefs, flag, parserContext) {
|
|
545
535
|
let boundedEdmxKind, boundedObj, boundedCsnKind, boundedEntityName, obj, paramName, paramObj, name;
|
|
546
536
|
if (flag == 0) {
|
|
547
537
|
boundedEdmxKind = "Action";
|
|
548
538
|
boundedCsnKind = "action";
|
|
549
|
-
boundedObj = boundedActions;
|
|
539
|
+
boundedObj = parserContext.boundedActions;
|
|
550
540
|
}
|
|
551
541
|
else {
|
|
552
542
|
boundedEdmxKind = "Function";
|
|
553
543
|
boundedCsnKind = "function";
|
|
554
|
-
boundedObj = boundedFunctions;
|
|
544
|
+
boundedObj = parserContext.boundedFunctions;
|
|
555
545
|
}
|
|
556
546
|
if (Object.keys(boundedObj).length > 0) {
|
|
557
547
|
Object.keys(boundedObj).forEach(b => {
|
|
@@ -561,13 +551,13 @@ function _parseBounded(csnDefs, flag) {
|
|
|
561
551
|
obj = boundedObj[b];
|
|
562
552
|
boundedEntityName = obj[j].$Parameter[0].$Type;
|
|
563
553
|
if (csnDefs[boundedEntityName] === undefined) {
|
|
564
|
-
boundedEntityName = namespace + "." + entitySetToEntityTypeMap.get(boundedEntityName)[0];
|
|
554
|
+
boundedEntityName = parserContext.namespace + "." + parserContext.entitySetToEntityTypeMap.get(boundedEntityName)[0];
|
|
565
555
|
}
|
|
566
556
|
if (csnDefs[boundedEntityName]) {
|
|
567
557
|
if (csnDefs[boundedEntityName].actions === undefined)
|
|
568
558
|
csnDefs[boundedEntityName].actions = {};
|
|
569
559
|
csnDefs[boundedEntityName].actions[name] = {};
|
|
570
|
-
_includeExternalNamespaceAnnotation(obj[0],csnDefs[boundedEntityName].actions[name]);
|
|
560
|
+
_includeExternalNamespaceAnnotation(obj[0], csnDefs[boundedEntityName].actions[name]);
|
|
571
561
|
csnDefs[boundedEntityName].actions[name].kind = boundedCsnKind;
|
|
572
562
|
// add params
|
|
573
563
|
if (obj[j].$Parameter && obj[j].$Parameter.length >= 2) {
|
|
@@ -586,16 +576,15 @@ function _parseBounded(csnDefs, flag) {
|
|
|
586
576
|
paramName = obj[j].$Parameter[i].$Name;
|
|
587
577
|
let paramType = {};
|
|
588
578
|
let annotations = {};
|
|
589
|
-
_includeExternalNamespaceAnnotation(paramObj,annotations);
|
|
579
|
+
_includeExternalNamespaceAnnotation(paramObj, annotations);
|
|
590
580
|
//check if the parameter type is pre-defined, undefined or custom defined
|
|
591
581
|
if (edmxncdsdatatype[paramObj.$Type] || edmxncdsdatatype[paramObj.$Type + "_a"])
|
|
592
582
|
paramType = generatePropertyCsn(paramObj, false);
|
|
593
583
|
else {
|
|
594
|
-
let type = _getDatatype(paramObj.$Type);
|
|
595
|
-
if(type) paramType["type"] = type;
|
|
584
|
+
let type = _getDatatype(paramObj.$Type, parserContext);
|
|
585
|
+
if (type) paramType["type"] = type;
|
|
596
586
|
}
|
|
597
|
-
if(Object.keys(paramType).length > 0)
|
|
598
|
-
{
|
|
587
|
+
if (Object.keys(paramType).length > 0) {
|
|
599
588
|
if (paramType.type || paramType.items.type) {
|
|
600
589
|
// check if parameter type is a collection
|
|
601
590
|
if (paramObj.$Collection && !paramType.items) {
|
|
@@ -603,15 +592,15 @@ function _parseBounded(csnDefs, flag) {
|
|
|
603
592
|
csnDefs[boundedEntityName].actions[name].params[paramName].items = paramType;
|
|
604
593
|
} else
|
|
605
594
|
csnDefs[boundedEntityName].actions[name].params[paramName] = paramType;
|
|
606
|
-
}
|
|
595
|
+
}
|
|
607
596
|
}
|
|
608
597
|
else {
|
|
609
|
-
let message = '"' + paramObj.$Type + '" is not supported (in element:"' + name + '")';
|
|
598
|
+
let message = '"' + paramObj.$Type + '" is not supported (in element:"' + name + '")';
|
|
610
599
|
console.log(warn(message));
|
|
611
600
|
}
|
|
612
|
-
if(csnDefs[boundedEntityName].actions[name].params[paramName])
|
|
601
|
+
if (csnDefs[boundedEntityName].actions[name].params[paramName])
|
|
613
602
|
Object.assign(csnDefs[boundedEntityName].actions[name].params[paramName], annotations);
|
|
614
|
-
}
|
|
603
|
+
}
|
|
615
604
|
}
|
|
616
605
|
}
|
|
617
606
|
//if parameters has no entries
|
|
@@ -626,11 +615,11 @@ function _parseBounded(csnDefs, flag) {
|
|
|
626
615
|
if (edmxncdsdatatype[obj[j].$ReturnType.$Type] || edmxncdsdatatype[obj[j].$ReturnType.$Type + "_a"])
|
|
627
616
|
returnType = generatePropertyCsn(obj[j].$ReturnType, false);
|
|
628
617
|
else {
|
|
629
|
-
let type = _getDatatype(obj[j].$ReturnType.$Type);
|
|
630
|
-
_includeExternalNamespaceAnnotation(obj[j].$ReturnType,annotations);
|
|
631
|
-
if(type) returnType["type"] = type
|
|
618
|
+
let type = _getDatatype(obj[j].$ReturnType.$Type, parserContext);
|
|
619
|
+
_includeExternalNamespaceAnnotation(obj[j].$ReturnType, annotations);
|
|
620
|
+
if (type) returnType["type"] = type;
|
|
632
621
|
}
|
|
633
|
-
if(Object.keys(returnType).length > 0){
|
|
622
|
+
if (Object.keys(returnType).length > 0) {
|
|
634
623
|
if (returnType.type || returnType.items.type) {
|
|
635
624
|
csnDefs[boundedEntityName].actions[name].returns = {};
|
|
636
625
|
// check if return type is a collection
|
|
@@ -638,12 +627,12 @@ function _parseBounded(csnDefs, flag) {
|
|
|
638
627
|
csnDefs[boundedEntityName].actions[name].returns.items = returnType;
|
|
639
628
|
else
|
|
640
629
|
csnDefs[boundedEntityName].actions[name].returns = returnType;
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
let message = '"' + obj[j].$ReturnType.$Type + '" is not supported (in return type)';
|
|
630
|
+
}
|
|
631
|
+
} else {
|
|
632
|
+
let message = '"' + obj[j].$ReturnType.$Type + '" is not supported (in return type)';
|
|
644
633
|
console.log(warn(message));
|
|
645
634
|
}
|
|
646
|
-
if(csnDefs[boundedEntityName].actions[name].returns)
|
|
635
|
+
if (csnDefs[boundedEntityName].actions[name].returns)
|
|
647
636
|
Object.assign(csnDefs[boundedEntityName].actions[name].returns, annotations)
|
|
648
637
|
}
|
|
649
638
|
}
|
|
@@ -652,13 +641,13 @@ function _parseBounded(csnDefs, flag) {
|
|
|
652
641
|
}
|
|
653
642
|
}
|
|
654
643
|
|
|
655
|
-
function _generateComplexType(schemaData) {
|
|
644
|
+
function _generateComplexType(schemaData, parserContext) {
|
|
656
645
|
let complexTypeDict = {};
|
|
657
646
|
let temp;
|
|
658
647
|
Object.keys(schemaData).forEach(curComplexType => {
|
|
659
648
|
if (schemaData[curComplexType] instanceof Object) {
|
|
660
649
|
if (schemaData[curComplexType].$Kind && schemaData[curComplexType].$Kind === 'ComplexType') {
|
|
661
|
-
temp = namespace + '.' + curComplexType;
|
|
650
|
+
temp = parserContext.namespace + '.' + curComplexType;
|
|
662
651
|
complexTypeDict[temp] = schemaData[curComplexType];
|
|
663
652
|
}
|
|
664
653
|
}
|
|
@@ -666,22 +655,22 @@ function _generateComplexType(schemaData) {
|
|
|
666
655
|
return complexTypeDict;
|
|
667
656
|
}
|
|
668
657
|
|
|
669
|
-
function _collectComplexType(schemaDataList) {
|
|
658
|
+
function _collectComplexType(schemaDataList, parserContext) {
|
|
670
659
|
// collect complex types
|
|
671
660
|
let schemaData;
|
|
672
661
|
for (let i = 0; i < schemaDataList.length; i++) {
|
|
673
662
|
schemaData = schemaDataList[i];
|
|
674
|
-
complexTypes = _generateComplexType(schemaData);
|
|
663
|
+
parserContext.complexTypes = _generateComplexType(schemaData, parserContext);
|
|
675
664
|
}
|
|
676
|
-
return complexTypes;
|
|
665
|
+
return parserContext.complexTypes;
|
|
677
666
|
}
|
|
678
667
|
|
|
679
|
-
function _generateCSNForComplexType(schemaData) {
|
|
668
|
+
function _generateCSNForComplexType(schemaData, parserContext) {
|
|
680
669
|
let complexCsn = {};
|
|
681
670
|
let cTypes;
|
|
682
671
|
let propertyType;
|
|
683
672
|
let baseType;
|
|
684
|
-
cTypes = _collectComplexType(schemaData);
|
|
673
|
+
cTypes = _collectComplexType(schemaData, parserContext);
|
|
685
674
|
Object.keys(cTypes).forEach(element => {
|
|
686
675
|
complexCsn[element] = {};
|
|
687
676
|
complexCsn[element].kind = 'type';
|
|
@@ -694,10 +683,13 @@ function _generateCSNForComplexType(schemaData) {
|
|
|
694
683
|
}
|
|
695
684
|
Object.keys(cTypes[element]).forEach(property => { // cTypes[element][property].$Type.startsWith('Edm.')
|
|
696
685
|
if (cTypes[element][property] instanceof Object) {
|
|
697
|
-
if (!cTypes[element][property].$Type ||
|
|
686
|
+
if (!cTypes[element][property].$Type ||
|
|
687
|
+
edmxncdsdatatype[cTypes[element][property].$Type] ||
|
|
688
|
+
edmxncdsdatatype[cTypes[element][property].$Type + "_a"]
|
|
689
|
+
) {
|
|
698
690
|
propertyType = cTypes[element][property];
|
|
699
691
|
complexCsn[element].elements[property] = generatePropertyCsn(propertyType, false);
|
|
700
|
-
} else if (complexTypes[cTypes[element][property].$Type]) {
|
|
692
|
+
} else if (parserContext.complexTypes[cTypes[element][property].$Type]) {
|
|
701
693
|
propertyType = cTypes[element][property];
|
|
702
694
|
complexCsn[element].elements[property] = _generateComplexTypePropertyCsn(propertyType);
|
|
703
695
|
} else {
|
|
@@ -712,59 +704,61 @@ function _generateCSNForComplexType(schemaData) {
|
|
|
712
704
|
return complexCsn;
|
|
713
705
|
}
|
|
714
706
|
|
|
715
|
-
function _parseTypeDefinition() {
|
|
707
|
+
function _parseTypeDefinition(parserContext) {
|
|
716
708
|
let typeDef = {};
|
|
717
709
|
let propertyType;
|
|
718
|
-
Object.keys(typeDefinitions).forEach(element => {
|
|
710
|
+
Object.keys(parserContext.typeDefinitions).forEach(element => {
|
|
719
711
|
typeDef[element] = {};
|
|
720
712
|
typeDef[element].kind = 'type';
|
|
721
|
-
if (!typeDefinitions[element].$Type ||
|
|
722
|
-
|
|
713
|
+
if (!parserContext.typeDefinitions[element].$Type ||
|
|
714
|
+
edmxncdsdatatype[parserContext.typeDefinitions[element].$Type]
|
|
715
|
+
) {
|
|
716
|
+
propertyType = parserContext.typeDefinitions[element];
|
|
723
717
|
typeDef[element] = Object.assign(typeDef[element], generatePropertyCsn(propertyType, false));
|
|
724
718
|
}
|
|
725
719
|
});
|
|
726
720
|
return typeDef;
|
|
727
721
|
}
|
|
728
722
|
|
|
729
|
-
function _parseUnbounded(schemaData, flag) {
|
|
723
|
+
function _parseUnbounded(schemaData, flag, parserContext) {
|
|
730
724
|
let unboundedObj = {}, unbounded, unboundedCsnKind;
|
|
731
725
|
let importToMap = new Multimap();
|
|
732
726
|
if (flag == 0) {
|
|
733
|
-
unbounded = unboundedActions;
|
|
734
|
-
importToMap = actionImportToActionMap;
|
|
727
|
+
unbounded = parserContext.unboundedActions;
|
|
728
|
+
importToMap = parserContext.actionImportToActionMap;
|
|
735
729
|
unboundedCsnKind = "action";
|
|
736
730
|
}
|
|
737
731
|
else {
|
|
738
|
-
unbounded = unboundedFunctions;
|
|
739
|
-
importToMap = functionImportToFunctionMap;
|
|
732
|
+
unbounded = parserContext.unboundedFunctions;
|
|
733
|
+
importToMap = parserContext.functionImportToFunctionMap;
|
|
740
734
|
unboundedCsnKind = "function";
|
|
741
735
|
}
|
|
742
736
|
if (Object.keys(unbounded).length > 0) {
|
|
743
737
|
Object.keys(unbounded).forEach(ub => {
|
|
744
738
|
let obj = {};
|
|
745
739
|
let objType = {}, objData = {}, temp = {};
|
|
746
|
-
if (importToMap && importToMap.get(ub)) {
|
|
740
|
+
if (importToMap && importToMap.get(ub)) {
|
|
747
741
|
temp = ub.split(".").pop();
|
|
748
|
-
objType = namespace + "." + temp;
|
|
742
|
+
objType = parserContext.namespace + "." + temp;
|
|
749
743
|
objData = schemaData[0][temp][0];
|
|
750
744
|
obj[objType] = {};
|
|
751
745
|
obj[objType].kind = unboundedCsnKind;
|
|
752
|
-
_includeExternalNamespaceAnnotation(objData,obj[objType]);
|
|
746
|
+
_includeExternalNamespaceAnnotation(objData, obj[objType]);
|
|
753
747
|
// add params
|
|
754
748
|
if (objData.$Parameter && objData.$Parameter.length > 0) {
|
|
755
|
-
obj[objType].params = {};
|
|
749
|
+
obj[objType].params = {};
|
|
756
750
|
for (let i = 0; i < objData.$Parameter.length; i++) {
|
|
757
751
|
let paramType = {};
|
|
758
752
|
let annotations = {};
|
|
759
753
|
_includeExternalNamespaceAnnotation(objData.$Parameter[i], annotations);
|
|
760
754
|
// check if the parameter type is pre-defined, undefined or custom defined
|
|
761
755
|
if (edmxncdsdatatype[objData.$Parameter[i].$Type] || edmxncdsdatatype[objData.$Parameter[i].$Type + "_a"]) {
|
|
762
|
-
paramType = generatePropertyCsn(objData.$Parameter[i],false)
|
|
756
|
+
paramType = generatePropertyCsn(objData.$Parameter[i], false)
|
|
763
757
|
} else {
|
|
764
|
-
let type = _getDatatype(objData.$Parameter[i].$Type);
|
|
765
|
-
if(type) paramType["type"] = type;
|
|
758
|
+
let type = _getDatatype(objData.$Parameter[i].$Type, parserContext);
|
|
759
|
+
if (type) paramType["type"] = type;
|
|
766
760
|
}
|
|
767
|
-
if(Object.keys(paramType).length > 0){
|
|
761
|
+
if (Object.keys(paramType).length > 0) {
|
|
768
762
|
if (paramType.type || paramType.items.type) {
|
|
769
763
|
// check if parameter type is a collection
|
|
770
764
|
if (objData.$Parameter[i].$Collection && !paramType.items) {
|
|
@@ -772,12 +766,12 @@ function _parseUnbounded(schemaData, flag) {
|
|
|
772
766
|
obj[objType].params[objData.$Parameter[i].$Name].items = paramType;
|
|
773
767
|
} else
|
|
774
768
|
obj[objType].params[objData.$Parameter[i].$Name] = paramType;
|
|
775
|
-
}
|
|
776
|
-
}else {
|
|
777
|
-
let message = '"' + objData.$Parameter[i].$Type + '" is not supported (in element:"' + temp + '")';
|
|
769
|
+
}
|
|
770
|
+
} else {
|
|
771
|
+
let message = '"' + objData.$Parameter[i].$Type + '" is not supported (in element:"' + temp + '")';
|
|
778
772
|
console.log(warn(message));
|
|
779
773
|
}
|
|
780
|
-
if(obj[objType].params[objData.$Parameter[i].$Name])
|
|
774
|
+
if (obj[objType].params[objData.$Parameter[i].$Name])
|
|
781
775
|
Object.assign(obj[objType].params[objData.$Parameter[i].$Name], annotations)
|
|
782
776
|
}
|
|
783
777
|
}
|
|
@@ -793,11 +787,11 @@ function _parseUnbounded(schemaData, flag) {
|
|
|
793
787
|
if (edmxncdsdatatype[objData.$ReturnType.$Type] || edmxncdsdatatype[objData.$ReturnType.$Type + "_a"]) {
|
|
794
788
|
returnValue = generatePropertyCsn(objData.$ReturnType, false);
|
|
795
789
|
} else {
|
|
796
|
-
let type = _getDatatype(objData.$ReturnType.$Type);
|
|
797
|
-
_includeExternalNamespaceAnnotation(objData.$ReturnType,annotations);
|
|
798
|
-
if(type) returnValue["type"] = type;
|
|
790
|
+
let type = _getDatatype(objData.$ReturnType.$Type, parserContext);
|
|
791
|
+
_includeExternalNamespaceAnnotation(objData.$ReturnType, annotations);
|
|
792
|
+
if (type) returnValue["type"] = type;
|
|
799
793
|
}
|
|
800
|
-
if(Object.keys(returnValue).length > 0){
|
|
794
|
+
if (Object.keys(returnValue).length > 0) {
|
|
801
795
|
if (returnValue.type || returnValue.items.type) {
|
|
802
796
|
obj[objType].returns = {};
|
|
803
797
|
// check if return type is a collection
|
|
@@ -807,12 +801,12 @@ function _parseUnbounded(schemaData, flag) {
|
|
|
807
801
|
} else
|
|
808
802
|
obj[objType].returns = returnValue;
|
|
809
803
|
}
|
|
810
|
-
}
|
|
804
|
+
}
|
|
811
805
|
else {
|
|
812
|
-
let message = '"' + objData.$ReturnType.$Type + '" is not supported (in return type of' + temp + ')';
|
|
806
|
+
let message = '"' + objData.$ReturnType.$Type + '" is not supported (in return type of' + temp + ')';
|
|
813
807
|
console.log(warn(message));
|
|
814
808
|
}
|
|
815
|
-
if(obj[objType].returns)
|
|
809
|
+
if (obj[objType].returns)
|
|
816
810
|
Object.assign(obj[objType].returns, annotations);
|
|
817
811
|
}
|
|
818
812
|
}
|
|
@@ -822,7 +816,7 @@ function _parseUnbounded(schemaData, flag) {
|
|
|
822
816
|
return unboundedObj;
|
|
823
817
|
}
|
|
824
818
|
|
|
825
|
-
function _generateCSN(edmxAsJson, ignorePersistenceSkip, mockServerUc) {
|
|
819
|
+
function _generateCSN(edmxAsJson, ignorePersistenceSkip, mockServerUc, parserContext) {
|
|
826
820
|
let csn = {};
|
|
827
821
|
let schemaData = [];
|
|
828
822
|
csn.meta = {};
|
|
@@ -840,7 +834,7 @@ function _generateCSN(edmxAsJson, ignorePersistenceSkip, mockServerUc) {
|
|
|
840
834
|
});
|
|
841
835
|
|
|
842
836
|
if (mockServerUc) {
|
|
843
|
-
let entitySetData = edmxAsJson[namespace];
|
|
837
|
+
let entitySetData = edmxAsJson[parserContext.namespace];
|
|
844
838
|
let entityContainer;
|
|
845
839
|
Object.keys(entitySetData).forEach(data => {
|
|
846
840
|
if (ignoreObjects.indexOf(data) === -1 && entitySetData[data] instanceof Object) {
|
|
@@ -852,42 +846,42 @@ function _generateCSN(edmxAsJson, ignorePersistenceSkip, mockServerUc) {
|
|
|
852
846
|
Object.keys(entityContainer).forEach(data => {
|
|
853
847
|
if (ignoreObjects.indexOf(data) === -1 && entityContainer[data] instanceof Object &&
|
|
854
848
|
entityContainer[data].$Type && entityContainer[data].$Collection) {
|
|
855
|
-
entitySetToEntityTypeMap.set(entityContainer[data].$Type, data);
|
|
849
|
+
parserContext.entitySetToEntityTypeMap.set(entityContainer[data].$Type, data);
|
|
856
850
|
} else if (ignoreObjects.indexOf(data) === -1 && entityContainer[data] instanceof Object &&
|
|
857
851
|
entityContainer[data].$Action) {
|
|
858
|
-
actionImportToActionMap.set(entityContainer[data].$Action, data);
|
|
859
|
-
unboundedActions[entityContainer[data].$Action] = entitySetData[data];
|
|
852
|
+
parserContext.actionImportToActionMap.set(entityContainer[data].$Action, data);
|
|
853
|
+
parserContext.unboundedActions[entityContainer[data].$Action] = entitySetData[data];
|
|
860
854
|
} else if (ignoreObjects.indexOf(data) === -1 && entityContainer[data] instanceof Object &&
|
|
861
855
|
entityContainer[data].$Function) {
|
|
862
|
-
functionImportToFunctionMap.set(entityContainer[data].$Function, data);
|
|
863
|
-
unboundedFunctions[entityContainer[data].$Function] = entitySetData[data];
|
|
856
|
+
parserContext.functionImportToFunctionMap.set(entityContainer[data].$Function, data);
|
|
857
|
+
parserContext.unboundedFunctions[entityContainer[data].$Function] = entitySetData[data];
|
|
864
858
|
}
|
|
865
859
|
});
|
|
866
860
|
}
|
|
867
861
|
|
|
868
|
-
csn.definitions[namespace] = {};
|
|
869
|
-
csn.definitions[namespace].kind = 'service';
|
|
870
|
-
csn.definitions[namespace]['@cds.external'] = true;
|
|
862
|
+
csn.definitions[parserContext.namespace] = {};
|
|
863
|
+
csn.definitions[parserContext.namespace].kind = 'service';
|
|
864
|
+
csn.definitions[parserContext.namespace]['@cds.external'] = true;
|
|
871
865
|
|
|
872
|
-
_collectEnumType(schemaData);
|
|
873
|
-
_collectTypeDefinition(schemaData);
|
|
874
|
-
_collectBounded(schemaData, 0);
|
|
875
|
-
_collectBounded(schemaData, 1);
|
|
866
|
+
_collectEnumType(schemaData, parserContext);
|
|
867
|
+
_collectTypeDefinition(schemaData, parserContext);
|
|
868
|
+
_collectBounded(schemaData, 0, parserContext);
|
|
869
|
+
_collectBounded(schemaData, 1, parserContext);
|
|
876
870
|
|
|
877
871
|
// Step 1: get all complex types.
|
|
878
|
-
csn.definitions = Object.assign(_generateCSNForComplexType(schemaData), csn.definitions);
|
|
872
|
+
csn.definitions = Object.assign(_generateCSNForComplexType(schemaData, parserContext), csn.definitions);
|
|
879
873
|
// Step 2: get all type definition
|
|
880
|
-
csn.definitions = Object.assign(_parseTypeDefinition(), csn.definitions);
|
|
874
|
+
csn.definitions = Object.assign(_parseTypeDefinition(parserContext), csn.definitions);
|
|
881
875
|
// Step 3: get all entity type
|
|
882
|
-
csn.definitions = Object.assign(_parseEntityType(schemaData, ignorePersistenceSkip, mockServerUc), csn.definitions);
|
|
876
|
+
csn.definitions = Object.assign(_parseEntityType(schemaData, ignorePersistenceSkip, mockServerUc, parserContext), csn.definitions);
|
|
883
877
|
// Step 4: get all unbounded action & function
|
|
884
|
-
csn.definitions = Object.assign(_parseUnbounded(schemaData, 0), csn.definitions);
|
|
885
|
-
csn.definitions = Object.assign(_parseUnbounded(schemaData ,
|
|
878
|
+
csn.definitions = Object.assign(_parseUnbounded(schemaData, 0, parserContext), csn.definitions);
|
|
879
|
+
csn.definitions = Object.assign(_parseUnbounded(schemaData, 1, parserContext), csn.definitions);
|
|
886
880
|
// Step 5: add entity container properties
|
|
887
|
-
csn.definitions = Object.assign(_parseEntityContainer(csn.definitions,schemaData),csn.definitions);
|
|
881
|
+
csn.definitions = Object.assign(_parseEntityContainer(csn.definitions, schemaData, parserContext, parserContext), csn.definitions);
|
|
888
882
|
// Step 6: get all bounded action & function
|
|
889
|
-
_parseBounded(csn.definitions, 0);
|
|
890
|
-
_parseBounded(csn.definitions, 1);
|
|
883
|
+
_parseBounded(csn.definitions, 0, parserContext);
|
|
884
|
+
_parseBounded(csn.definitions, 1, parserContext);
|
|
891
885
|
// Step 7: get all annotations
|
|
892
886
|
_generateDocumentation(schemaData, csn.definitions);
|
|
893
887
|
|
|
@@ -898,52 +892,52 @@ function _replaceSpecialCharacters(text) {
|
|
|
898
892
|
return text.replace(/(?:\\[rn]|[\r\n]+)+/gm, "\n").replace(/\s+/g, ' ').replace(/"/g, """).trim();
|
|
899
893
|
}
|
|
900
894
|
|
|
901
|
-
function _checkAnnotatationTerm(annotation, path, no_of_terms, targetString){
|
|
902
|
-
|
|
903
|
-
if(targetString === "@Core.Description" && annotation[1]["@Core.Description"]){
|
|
904
|
-
if(path.doc === undefined)
|
|
895
|
+
function _checkAnnotatationTerm(annotation, path, no_of_terms, targetString) {
|
|
896
|
+
if (path) {
|
|
897
|
+
if (targetString === "@Core.Description" && annotation[1]["@Core.Description"]) {
|
|
898
|
+
if (path.doc === undefined)
|
|
905
899
|
path.doc = _replaceSpecialCharacters(annotation[1]["@Core.Description"]);
|
|
906
900
|
else
|
|
907
901
|
path.doc += _replaceSpecialCharacters(annotation[1]["@Core.Description"]);
|
|
908
902
|
}
|
|
909
|
-
else if(targetString === "@Core.LongDescription" && annotation[1]["@Core.LongDescription"]){
|
|
910
|
-
_generateLongDescription(annotation,path,no_of_terms);
|
|
903
|
+
else if (targetString === "@Core.LongDescription" && annotation[1]["@Core.LongDescription"]) {
|
|
904
|
+
_generateLongDescription(annotation, path, no_of_terms);
|
|
911
905
|
}
|
|
912
906
|
}
|
|
913
907
|
}
|
|
914
|
-
function _checkAnnotationTarget(annotation, cdsDefs
|
|
908
|
+
function _checkAnnotationTarget(annotation, cdsDefs, str, no_of_terms) {
|
|
915
909
|
if (annotation[0].indexOf('/') === -1 && annotation[0].indexOf('(') === -1) {
|
|
916
910
|
if (annotation[0].endsWith(".EntityContainer")) {
|
|
917
911
|
let path = annotation[0].split(".")[0];
|
|
918
|
-
|
|
919
|
-
_checkAnnotatationTerm(annotation,cdsDefs[path],no_of_terms,str);
|
|
912
|
+
|
|
913
|
+
_checkAnnotatationTerm(annotation, cdsDefs[path], no_of_terms, str);
|
|
920
914
|
}
|
|
921
915
|
if (cdsDefs[annotation[0]]) {
|
|
922
|
-
_checkAnnotatationTerm(annotation, cdsDefs[annotation[0]], no_of_terms
|
|
916
|
+
_checkAnnotatationTerm(annotation, cdsDefs[annotation[0]], no_of_terms, str);
|
|
923
917
|
}
|
|
924
|
-
} else if(annotation[0].indexOf('(') === -1 && !(annotation[0].indexOf('/') === -1)){
|
|
918
|
+
} else if (annotation[0].indexOf('(') === -1 && !(annotation[0].indexOf('/') === -1)) {
|
|
925
919
|
let path = annotation[0].split('/');
|
|
926
|
-
if(cdsDefs[path[0]]){
|
|
927
|
-
|
|
928
|
-
}
|
|
929
|
-
} else{
|
|
920
|
+
if (cdsDefs[path[0]]) {
|
|
921
|
+
_checkAnnotatationTerm(annotation, cdsDefs[path[0]]["elements"][path[1]], no_of_terms, str);
|
|
922
|
+
}
|
|
923
|
+
} else {
|
|
930
924
|
let path = annotation[0].split('(');
|
|
931
|
-
if(cdsDefs[path[0]]== undefined){
|
|
925
|
+
if (cdsDefs[path[0]] == undefined) {
|
|
932
926
|
let temp = path[1].split(')');
|
|
933
927
|
let path1 = temp[0].split(',');
|
|
934
928
|
let path2 = path[0].split('.');
|
|
935
|
-
if(cdsDefs[path1[0]]){
|
|
936
|
-
_checkAnnotatationTerm(annotation,cdsDefs[path1[0]]["actions"][path2[1]],no_of_terms,str);
|
|
929
|
+
if (cdsDefs[path1[0]]) {
|
|
930
|
+
_checkAnnotatationTerm(annotation, cdsDefs[path1[0]]["actions"][path2[1]], no_of_terms, str);
|
|
937
931
|
}
|
|
938
|
-
} else{
|
|
939
|
-
if(path[1].indexOf('/') === -1){
|
|
940
|
-
|
|
941
|
-
} else{
|
|
932
|
+
} else {
|
|
933
|
+
if (path[1].indexOf('/') === -1) {
|
|
934
|
+
_checkAnnotatationTerm(annotation, cdsDefs[path[0]], no_of_terms, str);
|
|
935
|
+
} else {
|
|
942
936
|
let path1 = path[1].split('/');
|
|
943
|
-
if(cdsDefs[path[0]] && cdsDefs[path[0]]["params"]){
|
|
944
|
-
_checkAnnotatationTerm(annotation,cdsDefs[path[0]]["params"][path1[1]],no_of_terms,str);
|
|
937
|
+
if (cdsDefs[path[0]] && cdsDefs[path[0]]["params"]) {
|
|
938
|
+
_checkAnnotatationTerm(annotation, cdsDefs[path[0]]["params"][path1[1]], no_of_terms, str);
|
|
945
939
|
}
|
|
946
|
-
}
|
|
940
|
+
}
|
|
947
941
|
}
|
|
948
942
|
}
|
|
949
943
|
}
|
|
@@ -956,79 +950,74 @@ function _generateDocumentation(schemaData, cdsDefs) {
|
|
|
956
950
|
if (annotation[1].hasOwnProperty('@Core.Description')) {
|
|
957
951
|
|
|
958
952
|
no_of_terms = true;
|
|
959
|
-
_checkAnnotationTarget(annotation,cdsDefs,"@Core.Description",no_of_terms);
|
|
953
|
+
_checkAnnotationTarget(annotation, cdsDefs, "@Core.Description", no_of_terms);
|
|
960
954
|
}
|
|
961
955
|
// eslint-disable-next-line no-prototype-builtins
|
|
962
956
|
if (annotation[1].hasOwnProperty('@Core.LongDescription')) {
|
|
963
|
-
_checkAnnotationTarget(annotation,cdsDefs,"@Core.LongDescription",no_of_terms);
|
|
957
|
+
_checkAnnotationTarget(annotation, cdsDefs, "@Core.LongDescription", no_of_terms);
|
|
964
958
|
|
|
965
|
-
|
|
959
|
+
}
|
|
966
960
|
});
|
|
967
961
|
}
|
|
968
962
|
}
|
|
969
963
|
|
|
970
|
-
function _generateLongDescription(annotation,path,no_of_terms){
|
|
971
|
-
if(path){
|
|
972
|
-
path.doc = no_of_terms ? (path.doc += "\n\n") : (path.doc ? (path.doc+="") : (path.doc=""));
|
|
964
|
+
function _generateLongDescription(annotation, path, no_of_terms) {
|
|
965
|
+
if (path) {
|
|
966
|
+
path.doc = no_of_terms ? (path.doc += "\n\n") : (path.doc ? (path.doc += "") : (path.doc = ""));
|
|
973
967
|
path.doc += _replaceSpecialCharacters(annotation[1]["@Core.LongDescription"]);
|
|
974
|
-
return(path.doc);
|
|
968
|
+
return (path.doc);
|
|
975
969
|
}
|
|
976
970
|
}
|
|
977
971
|
|
|
978
972
|
|
|
979
|
-
function _generateEDMX2JSON(edmx, name_space) {
|
|
980
|
-
return new Promise(function getJson(resolve, reject) {
|
|
981
|
-
try {
|
|
973
|
+
function _generateEDMX2JSON(edmx, name_space, parserContext) {
|
|
974
|
+
return new Promise(function getJson(resolve, reject) {
|
|
975
|
+
try {
|
|
982
976
|
const inputBuffer = edmx;
|
|
983
977
|
// create converter
|
|
984
978
|
const v4Conv = MetadataConverterFactory.createEdmxV40XmlToV40Json(name_space);
|
|
985
|
-
v4Conv.execute(inputBuffer, (error, json, missingReferencedDocuments) => {
|
|
979
|
+
v4Conv.execute(inputBuffer, (error, json, missingReferencedDocuments) => {
|
|
986
980
|
if (missingReferencedDocuments.length > 0) {
|
|
987
981
|
console.log(missingReferencedDocuments); // eslint-disable-line no-console
|
|
988
982
|
}
|
|
989
|
-
if (_validateJSON(json)) {
|
|
983
|
+
if (_validateJSON(json, parserContext)) {
|
|
990
984
|
resolve(json);
|
|
991
985
|
}
|
|
992
986
|
});
|
|
993
|
-
} catch (err) {
|
|
987
|
+
} catch (err) {
|
|
994
988
|
reject(err);
|
|
995
989
|
}
|
|
996
990
|
});
|
|
997
991
|
}
|
|
998
992
|
|
|
999
|
-
function getEdmxv4CSN(edmx, ignorePersistenceSkip, mockServerUc, context) {
|
|
993
|
+
async function getEdmxv4CSN(edmx, ignorePersistenceSkip, mockServerUc, context) {
|
|
1000
994
|
let csn;
|
|
1001
995
|
let edmjConverted;
|
|
1002
996
|
let name_space = []
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
997
|
+
|
|
998
|
+
const parserContext = {};
|
|
999
|
+
_initialize(parserContext);
|
|
1000
|
+
|
|
1001
|
+
if (context.include_all_namespaces === true)
|
|
1006
1002
|
name_space.push(true);
|
|
1007
|
-
|
|
1008
|
-
else{
|
|
1003
|
+
else
|
|
1009
1004
|
name_space = context.namespaces;
|
|
1010
|
-
|
|
1005
|
+
|
|
1011
1006
|
if (_isJson(edmx)) {
|
|
1012
1007
|
return new Promise(function getCsn(resolve, reject) {
|
|
1013
1008
|
try {
|
|
1014
1009
|
edmjConverted = JSON.parse(edmx);
|
|
1015
|
-
if (_validateJSON(edmjConverted)) {
|
|
1016
|
-
csn = _generateCSN(edmjConverted, ignorePersistenceSkip, mockServerUc);
|
|
1017
|
-
if (csn)
|
|
1018
|
-
resolve(csn);
|
|
1019
|
-
} else {
|
|
1020
|
-
reject(errors);
|
|
1021
|
-
}
|
|
1010
|
+
if (_validateJSON(edmjConverted, parserContext)) {
|
|
1011
|
+
csn = _generateCSN(edmjConverted, ignorePersistenceSkip, mockServerUc, parserContext);
|
|
1012
|
+
if (csn) resolve(csn);
|
|
1022
1013
|
}
|
|
1023
1014
|
} catch (err) {
|
|
1024
1015
|
reject(err);
|
|
1025
1016
|
}
|
|
1026
1017
|
});
|
|
1027
1018
|
}
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
return _generateCSN(edmj, ignorePersistenceSkip, mockServerUc);
|
|
1031
|
-
});
|
|
1019
|
+
const edmj = await _generateEDMX2JSON(edmx, name_space, parserContext);
|
|
1020
|
+
return _generateCSN(edmj, ignorePersistenceSkip, mockServerUc, parserContext);
|
|
1032
1021
|
}
|
|
1033
1022
|
|
|
1034
1023
|
module.exports = {
|