@sap-ux/odata-service-writer 0.29.34 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data/defaults.js +61 -18
- package/package.json +2 -2
package/dist/data/defaults.js
CHANGED
|
@@ -137,36 +137,79 @@ function setDefaultAnnotationsName(service) {
|
|
|
137
137
|
setDefaultAnnotationName(annotation, service.name);
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Sets client and destination defaults for preview settings.
|
|
142
|
+
*
|
|
143
|
+
* @param {OdataService} service - the OData service instance
|
|
144
|
+
*/
|
|
145
|
+
function setClientAndDestinationDefaults(service) {
|
|
146
|
+
if (service.client && !service.previewSettings?.client) {
|
|
147
|
+
service.previewSettings.client = service.client;
|
|
148
|
+
}
|
|
149
|
+
if (service.destination && !service.previewSettings?.destination) {
|
|
150
|
+
service.previewSettings.destination = service.destination.name;
|
|
151
|
+
if (service.destination.instance) {
|
|
152
|
+
service.previewSettings.destinationInstance = service.destination.instance;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Preserves existing backend configuration when updating a service.
|
|
158
|
+
*
|
|
159
|
+
* @param {OdataService} service - the OData service instance
|
|
160
|
+
* @param {FioriToolsProxyConfigBackend[]} backends - existing backend configurations
|
|
161
|
+
* @param {string | undefined} explicitPreviewPath - explicitly set preview path
|
|
162
|
+
*/
|
|
163
|
+
function preserveExistingBackendConfig(service, backends, explicitPreviewPath) {
|
|
164
|
+
const existingBackend = backends.find((backend) => backend.path === service.previewSettings?.path);
|
|
165
|
+
if (!existingBackend) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (existingBackend.pathPrefix) {
|
|
169
|
+
service.previewSettings.pathPrefix = existingBackend.pathPrefix;
|
|
170
|
+
}
|
|
171
|
+
if (!explicitPreviewPath) {
|
|
172
|
+
service.previewSettings.path = service.path;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Adjusts preview path for new services if /sap backend exists.
|
|
177
|
+
*
|
|
178
|
+
* @param {OdataService} service - the OData service instance
|
|
179
|
+
* @param {FioriToolsProxyConfigBackend[]} backends - existing backend configurations
|
|
180
|
+
*/
|
|
181
|
+
function adjustPreviewPathForNewService(service, backends) {
|
|
182
|
+
if (backends.find((existingBackend) => existingBackend.path === '/sap')) {
|
|
183
|
+
service.previewSettings.path = service.path;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
140
186
|
/**
|
|
141
187
|
* Sets default preview settings of a given service.
|
|
142
188
|
*
|
|
143
189
|
* @param {string} basePath - the root path of an existing UI5 application
|
|
144
190
|
* @param {OdataService} service - The service object whose preview settings needs to be set or modified.
|
|
145
191
|
* @param {Editor} fs - the memfs editor instance
|
|
192
|
+
* @param {boolean} update - whether the service update is running (if true, preserves explicitly set previewSettings.path)
|
|
146
193
|
*/
|
|
147
|
-
async function setDefaultPreviewSettings(basePath, service, fs) {
|
|
194
|
+
async function setDefaultPreviewSettings(basePath, service, fs, update = false) {
|
|
148
195
|
service.previewSettings = service.previewSettings ?? {};
|
|
196
|
+
const explicitPreviewPath = service.previewSettings.path;
|
|
149
197
|
service.previewSettings.path =
|
|
150
198
|
service.previewSettings.path ?? `/${service.path?.split('/').find((s) => s !== '') ?? ''}`;
|
|
151
199
|
service.previewSettings.url = service.previewSettings.url ?? service.url ?? 'http://localhost';
|
|
152
|
-
|
|
153
|
-
|
|
200
|
+
setClientAndDestinationDefaults(service);
|
|
201
|
+
const ui5Yamlpath = (0, node_path_1.join)(basePath, project_access_1.FileName.Ui5Yaml);
|
|
202
|
+
if (!fs.exists(ui5Yamlpath)) {
|
|
203
|
+
return;
|
|
154
204
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
205
|
+
const yamlContents = fs.read(ui5Yamlpath);
|
|
206
|
+
const ui5Config = await ui5_config_1.UI5Config.newInstance(yamlContents);
|
|
207
|
+
const backends = ui5Config.getBackendConfigsFromFioriToolsProxyMiddleware();
|
|
208
|
+
if (update) {
|
|
209
|
+
preserveExistingBackendConfig(service, backends, explicitPreviewPath);
|
|
160
210
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const yamlContents = fs.read(ui5Yamlpath);
|
|
164
|
-
const ui5Config = await ui5_config_1.UI5Config.newInstance(yamlContents);
|
|
165
|
-
const backends = ui5Config.getBackendConfigsFromFioriToolsProxyMiddleware();
|
|
166
|
-
// There should be only one /sap entry
|
|
167
|
-
if (backends.find((existingBackend) => existingBackend.path === '/sap')) {
|
|
168
|
-
service.previewSettings.path = service.path;
|
|
169
|
-
}
|
|
211
|
+
else if (backends.find((existingBackend) => existingBackend.path === '/sap')) {
|
|
212
|
+
adjustPreviewPathForNewService(service, backends);
|
|
170
213
|
}
|
|
171
214
|
}
|
|
172
215
|
/**
|
|
@@ -195,6 +238,6 @@ async function enhanceData(basePath, service, fs, update = false) {
|
|
|
195
238
|
setDefaultAnnotationsName(service);
|
|
196
239
|
}
|
|
197
240
|
// enhance preview settings with service configuration
|
|
198
|
-
await setDefaultPreviewSettings(basePath, service, fs);
|
|
241
|
+
await setDefaultPreviewSettings(basePath, service, fs, update);
|
|
199
242
|
}
|
|
200
243
|
//# sourceMappingURL=defaults.js.map
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"bugs": {
|
|
10
10
|
"url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Aodata-service-writer"
|
|
11
11
|
},
|
|
12
|
-
"version": "0.
|
|
12
|
+
"version": "0.30.0",
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"main": "dist/index.js",
|
|
15
15
|
"files": [
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@types/semver": "7.7.1",
|
|
43
43
|
"fs-extra": "11.3.4",
|
|
44
44
|
"lodash": "4.17.23",
|
|
45
|
-
"@sap-ux/axios-extension": "1.25.
|
|
45
|
+
"@sap-ux/axios-extension": "1.25.22"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
|
48
48
|
"node": ">=20.x"
|