@sap-ux/odata-service-writer 0.14.28 → 0.14.30

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.
@@ -2,6 +2,50 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.enhanceData = void 0;
4
4
  const constants_1 = require("./constants");
5
+ /**
6
+ * Sets the default path for a given service.
7
+ * If the service path is not defined, it sets the path to '/'.
8
+ * If the service path does not end with '/', it appends '/' to the end.
9
+ *
10
+ * @param {OdataService} service - The service object whose path needs to be set or modified.
11
+ */
12
+ function setDefaultServicePath(service) {
13
+ var _a, _b;
14
+ service.path = ((_a = service.path) === null || _a === void 0 ? void 0 : _a.endsWith('/')) ? service.path : ((_b = service.path) !== null && _b !== void 0 ? _b : '') + '/';
15
+ }
16
+ /**
17
+ * Sets the default name for a given service.
18
+ * If the service name is not defined, it sets the name to `DEFAULT_DATASOURCE_NAME`.
19
+ *
20
+ * @param {OdataService} service - The service object whose name needs to be set or modified.
21
+ */
22
+ function setDefaultServiceName(service) {
23
+ var _a;
24
+ service.name = (_a = service.name) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_DATASOURCE_NAME;
25
+ }
26
+ /**
27
+ * Sets the default model for a given service.
28
+ * If the service model is not defined, it sets the model to an empty string (Default UI5 model).
29
+ *
30
+ * @param {OdataService} service - The service object whose model needs to be set or modified.
31
+ */
32
+ function setDefaultServiceModel(service) {
33
+ var _a;
34
+ service.model = (_a = service.model) !== null && _a !== void 0 ? _a : ''; // Default UI5 model
35
+ }
36
+ /**
37
+ * Sets the default annotations name for a given service.
38
+ * If the service annotations name is not defined or empty, it creates a default annotations name
39
+ * from the technicalName by replacing all '/' characters with '_' and removing the leading '_'.
40
+ *
41
+ * @param {OdataService} service - The service object whose annotations name needs to be set or modified.
42
+ */
43
+ function setDefaultAnnotationsName(service) {
44
+ var _a, _b, _c, _d;
45
+ if (((_a = service.annotations) === null || _a === void 0 ? void 0 : _a.technicalName) && !service.annotations.name) {
46
+ service.annotations.name = (_d = (_c = (_b = service.annotations) === null || _b === void 0 ? void 0 : _b.technicalName) === null || _c === void 0 ? void 0 : _c.replace(/\//g, '_')) === null || _d === void 0 ? void 0 : _d.replace(/^_/, '');
47
+ }
48
+ }
5
49
  /**
6
50
  * Enhances the provided OData service object with path, name and model information.
7
51
  * Directly modifies the passed object reference.
@@ -9,24 +53,15 @@ const constants_1 = require("./constants");
9
53
  * @param {OdataService} service - the OData service object
10
54
  */
11
55
  function enhanceData(service) {
12
- var _a;
13
- // Set default path
14
- if (service.path === undefined) {
15
- service.path = '/';
16
- }
17
- else if (service.path.substring(service.path.length - 1) !== '/') {
18
- service.path = service.path + '/';
19
- }
20
- if (service.name === undefined) {
21
- service.name = constants_1.DEFAULT_DATASOURCE_NAME;
22
- }
23
- if (service.model === undefined) {
24
- service.model = ''; // Default UI5 model
25
- }
56
+ var _a, _b;
57
+ setDefaultServicePath(service);
58
+ setDefaultServiceName(service);
59
+ setDefaultServiceModel(service);
60
+ setDefaultAnnotationsName(service);
26
61
  // enhance preview settings with service configuration
27
62
  service.previewSettings = service.previewSettings || {};
28
63
  service.previewSettings.path =
29
- service.previewSettings.path || `/${((_a = service.path) === null || _a === void 0 ? void 0 : _a.split('/').filter((s) => s !== '')[0]) || ''}`;
64
+ service.previewSettings.path || `/${(_b = (_a = service.path) === null || _a === void 0 ? void 0 : _a.split('/').filter((s) => s !== '')[0]) !== null && _b !== void 0 ? _b : ''}`;
30
65
  service.previewSettings.url = service.previewSettings.url || service.url || 'http://localhost';
31
66
  if (service.client && !service.previewSettings.client) {
32
67
  service.previewSettings.client = service.client;
package/dist/types.d.ts CHANGED
@@ -20,6 +20,7 @@ export interface OdataService {
20
20
  model?: string;
21
21
  metadata?: string;
22
22
  annotations?: {
23
+ name?: string;
23
24
  technicalName: string;
24
25
  xml: string;
25
26
  };
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.14.28",
12
+ "version": "0.14.30",
13
13
  "license": "Apache-2.0",
14
14
  "main": "dist/index.js",
15
15
  "files": [
@@ -6,7 +6,7 @@
6
6
  "type": "OData",
7
7
  "settings": {
8
8
  "annotations": [<%if (locals.annotations && annotations.technicalName) {%>
9
- "<%- annotations.technicalName %>"<% if (locals.localAnnotationsName) {%>,<%}%><% } %><% if (locals.localAnnotationsName) { %>
9
+ "<%- annotations.name %>"<% if (locals.localAnnotationsName) {%>,<%}%><% } %><% if (locals.localAnnotationsName) { %>
10
10
  "<%- localAnnotationsName %>"<% } %>
11
11
  ],
12
12
  "localUri": "localService/metadata.xml"<%if (version === '4') {%>,
@@ -14,7 +14,7 @@
14
14
  "odataVersion": "2.0"<% } %>
15
15
  }
16
16
  }<%if (locals.annotations && annotations.technicalName) {%>,
17
- "<%- annotations.technicalName %>": {
17
+ "<%- annotations.name %>": {
18
18
  "uri": "/sap/opu/odata/IWFND/CATALOGSERVICE;v=2/Annotations(TechnicalName='<%- encodeURIComponent(annotations.technicalName) %>',Version='0001')/$value/",
19
19
  "type": "ODataAnnotation",
20
20
  "settings": {