@sap-ux/odata-service-writer 0.26.11 → 0.26.13

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.
@@ -5,6 +5,7 @@ const path_1 = require("path");
5
5
  const types_1 = require("../types");
6
6
  const constants_1 = require("./constants");
7
7
  const project_access_1 = require("@sap-ux/project-access");
8
+ const ui5_config_1 = require("@sap-ux/ui5-config");
8
9
  /**
9
10
  * Sets the default path for a given service.
10
11
  * If the service path is not defined, it sets the path to '/'.
@@ -107,6 +108,38 @@ function setDefaultAnnotationsName(service) {
107
108
  setDefaultAnnotationName(annotation, service.name);
108
109
  }
109
110
  }
111
+ /**
112
+ * Sets default preview settings of a given service.
113
+ *
114
+ * @param {string} basePath - the root path of an existing UI5 application
115
+ * @param {OdataService} service - The service object whose preview settings needs to be set or modified.
116
+ * @param {Editor} fs - the memfs editor instance
117
+ */
118
+ async function setDefaultPreviewSettings(basePath, service, fs) {
119
+ service.previewSettings = service.previewSettings ?? {};
120
+ service.previewSettings.path =
121
+ service.previewSettings.path ?? `/${service.path?.split('/').filter((s) => s !== '')[0] ?? ''}`;
122
+ service.previewSettings.url = service.previewSettings.url ?? service.url ?? 'http://localhost';
123
+ if (service.client && !service.previewSettings.client) {
124
+ service.previewSettings.client = service.client;
125
+ }
126
+ if (service.destination && !service.previewSettings.destination) {
127
+ service.previewSettings.destination = service.destination.name;
128
+ if (service.destination.instance) {
129
+ service.previewSettings.destinationInstance = service.destination.instance;
130
+ }
131
+ }
132
+ const ui5Yamlpath = (0, path_1.join)(basePath, project_access_1.FileName.Ui5Yaml);
133
+ if (fs.exists(ui5Yamlpath)) {
134
+ const yamlContents = fs.read(ui5Yamlpath);
135
+ const ui5Config = await ui5_config_1.UI5Config.newInstance(yamlContents);
136
+ const backends = ui5Config.getBackendConfigsFromFioriToolsProxydMiddleware();
137
+ // There should be only one /sap entry
138
+ if (backends.find((existingBackend) => existingBackend.path === '/sap')) {
139
+ service.previewSettings.path = service.path;
140
+ }
141
+ }
142
+ }
110
143
  /**
111
144
  * Enhances the provided OData service object with path, name and model information.
112
145
  * Directly modifies the passed object reference.
@@ -130,18 +163,6 @@ async function enhanceData(basePath, service, fs) {
130
163
  setDefaultAnnotationsName(service);
131
164
  }
132
165
  // enhance preview settings with service configuration
133
- service.previewSettings = service.previewSettings ?? {};
134
- service.previewSettings.path =
135
- service.previewSettings.path ?? `/${service.path?.split('/').filter((s) => s !== '')[0] ?? ''}`;
136
- service.previewSettings.url = service.previewSettings.url ?? service.url ?? 'http://localhost';
137
- if (service.client && !service.previewSettings.client) {
138
- service.previewSettings.client = service.client;
139
- }
140
- if (service.destination && !service.previewSettings.destination) {
141
- service.previewSettings.destination = service.destination.name;
142
- if (service.destination.instance) {
143
- service.previewSettings.destinationInstance = service.destination.instance;
144
- }
145
- }
166
+ await setDefaultPreviewSettings(basePath, service, fs);
146
167
  }
147
168
  //# sourceMappingURL=defaults.js.map
package/dist/delete.js CHANGED
@@ -35,7 +35,7 @@ function getEDMXAnnotationPaths(edmxAnnotations) {
35
35
  */
36
36
  async function deleteServiceData(basePath, paths, service, fs) {
37
37
  (0, manifest_1.deleteServiceFromManifest)(basePath, service, fs);
38
- if (service.url && service.path && service.name) {
38
+ if (service.path && service.name) {
39
39
  let ui5Config;
40
40
  let ui5LocalConfig;
41
41
  let ui5MockConfig;
@@ -43,14 +43,14 @@ async function deleteServiceData(basePath, paths, service, fs) {
43
43
  if (paths.ui5Yaml) {
44
44
  ui5Config = await ui5_config_1.UI5Config.newInstance(fs.read(paths.ui5Yaml));
45
45
  // Delete service backend from fiori-tools-proxy middleware config
46
- ui5Config.removeBackendFromFioriToolsProxydMiddleware(service.url);
46
+ ui5Config.removeBackendFromFioriToolsProxydMiddleware(service.path);
47
47
  fs.write(paths.ui5Yaml, ui5Config.toString());
48
48
  }
49
49
  const serviceAnnotationPaths = getEDMXAnnotationPaths(service.annotations);
50
50
  if (paths.ui5LocalYaml) {
51
51
  ui5LocalConfig = await ui5_config_1.UI5Config.newInstance(fs.read(paths.ui5LocalYaml));
52
52
  // Delete service backend from fiori-tools-proxy middleware config
53
- ui5LocalConfig.removeBackendFromFioriToolsProxydMiddleware(service.url);
53
+ ui5LocalConfig.removeBackendFromFioriToolsProxydMiddleware(service.path);
54
54
  // Delete service from mockserver middleware config
55
55
  ui5LocalConfig.removeServiceFromMockServerMiddleware(service.path, serviceAnnotationPaths);
56
56
  fs.write(paths.ui5LocalYaml, ui5LocalConfig.toString());
@@ -58,7 +58,7 @@ async function deleteServiceData(basePath, paths, service, fs) {
58
58
  if (paths.ui5MockYaml) {
59
59
  ui5MockConfig = await ui5_config_1.UI5Config.newInstance(fs.read(paths.ui5MockYaml));
60
60
  // Delete service backend from fiori-tools-proxy middleware config
61
- ui5MockConfig.removeBackendFromFioriToolsProxydMiddleware(service.url);
61
+ ui5MockConfig.removeBackendFromFioriToolsProxydMiddleware(service.path);
62
62
  // Delete service from mockserver config
63
63
  ui5MockConfig.removeServiceFromMockServerMiddleware(service.path, serviceAnnotationPaths);
64
64
  fs.write(paths.ui5MockYaml, ui5MockConfig.toString());
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.26.11",
12
+ "version": "0.26.13",
13
13
  "license": "Apache-2.0",
14
14
  "main": "dist/index.js",
15
15
  "files": [
@@ -27,9 +27,9 @@
27
27
  "mem-fs-editor": "9.4.0",
28
28
  "prettify-xml": "1.2.0",
29
29
  "semver": "7.5.4",
30
- "@sap-ux/mockserver-config-writer": "0.8.9",
31
- "@sap-ux/project-access": "1.29.16",
32
- "@sap-ux/ui5-config": "0.26.4"
30
+ "@sap-ux/mockserver-config-writer": "0.8.11",
31
+ "@sap-ux/project-access": "1.29.18",
32
+ "@sap-ux/ui5-config": "0.26.5"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/ejs": "3.1.2",