@sap-ux/odata-service-writer 0.31.12 → 0.32.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.
@@ -8,16 +8,31 @@ exports.updateManifest = updateManifest;
8
8
  const node_path_1 = require("node:path");
9
9
  const i18n_1 = require("../i18n");
10
10
  const project_access_1 = require("@sap-ux/project-access");
11
+ const types_1 = require("../types");
11
12
  const semver_1 = __importDefault(require("semver"));
13
+ /**
14
+ * Extracts the OData version string to write to manifest.json from raw EDMX metadata.
15
+ * Only returns a value when the EDMX declares Version="4.01".
16
+ * All other version distinctions (v2 vs v4) remain the caller's responsibility.
17
+ *
18
+ * @param metadata - raw EDMX XML string
19
+ * @returns '4.01' when applicable, undefined otherwise
20
+ */
21
+ function getOdataVersionFromMetadata(metadata) {
22
+ // Scan only the first 500 chars to avoid processing large metadata strings.
23
+ // The XML declaration (<?xml ...?>) may precede the root <edmx:Edmx Version="..."> tag,
24
+ // so we cannot stop at the first '>'.
25
+ const match = /Version="([^"]+)"/.exec(metadata.slice(0, 500));
26
+ return match?.[1] === '4.01' ? '4.01' : undefined;
27
+ }
12
28
  /**
13
29
  * Updates service data in manifest.json.
14
30
  *
15
31
  * @param {Editor} fs - the memfs editor instance
16
32
  * @param {string} webappPath - the webapp path of an existing UI5 application
17
33
  * @param {DataSourceUpdateSettings} dataSourceUpdateSettings - dataSource settings for update
18
- * @param {string} minimumUi5Version - minimum UI5 version of the application
19
34
  */
20
- function enhanceManifestDatasources(fs, webappPath, dataSourceUpdateSettings, minimumUi5Version) {
35
+ function enhanceManifestDatasources(fs, webappPath, dataSourceUpdateSettings) {
21
36
  const { serviceName, servicePath, serviceVersion, manifest, forceServiceUpdate, serviceMetadata, serviceRemoteAnnotations, serviceLocalAnnotations } = dataSourceUpdateSettings;
22
37
  const dataSources = manifest?.['sap.app'].dataSources ?? {};
23
38
  const createdRemoteAnnotationDataSources = addRemoteAnnotationDataSources(fs, webappPath, dataSources, serviceName, serviceRemoteAnnotations, forceServiceUpdate);
@@ -28,11 +43,17 @@ function enhanceManifestDatasources(fs, webappPath, dataSourceUpdateSettings, mi
28
43
  if (serviceMetadata) {
29
44
  settings['localUri'] = `localService/${serviceName}/metadata.xml`;
30
45
  }
31
- if (serviceVersion === '4') {
32
- settings['odataVersion'] = minimumUi5Version && semver_1.default.satisfies(minimumUi5Version, '>=1.144') ? '4.01' : '4.0';
46
+ // Derive the manifest odataVersion: for v4 services, check EDMX metadata first (to detect 4.01),
47
+ // then fall back to the passed service version enum.
48
+ let odataVersionToWrite;
49
+ if (serviceVersion === types_1.OdataVersion.v4) {
50
+ odataVersionToWrite = (serviceMetadata && getOdataVersionFromMetadata(serviceMetadata)) || '4.0';
51
+ }
52
+ else if (serviceVersion === types_1.OdataVersion.v2) {
53
+ odataVersionToWrite = '2.0';
33
54
  }
34
- else if (serviceVersion === '2') {
35
- settings['odataVersion'] = '2.0';
55
+ if (odataVersionToWrite) {
56
+ settings['odataVersion'] = odataVersionToWrite;
36
57
  }
37
58
  // Create or update service dataSource in manifest.json for service
38
59
  dataSources[serviceName] = {
@@ -55,7 +76,7 @@ function enhanceManifestDatasources(fs, webappPath, dataSourceUpdateSettings, mi
55
76
  function enhanceManifestModels(serviceName, serviceVersion, serviceModel, includeSynchronizationMode, manifest) {
56
77
  const models = manifest?.['sap.ui5']?.models ?? {};
57
78
  let modelSettings = {};
58
- if (serviceVersion === '4') {
79
+ if (serviceVersion === types_1.OdataVersion.v4) {
59
80
  if (includeSynchronizationMode) {
60
81
  modelSettings['synchronizationMode'] = 'None';
61
82
  }
@@ -246,7 +267,7 @@ function enhanceManifest(service, manifest, webappPath, fs, forceServiceUpdate)
246
267
  serviceMetadata: serviceSettings.metadata,
247
268
  serviceRemoteAnnotations: serviceSettings.annotations,
248
269
  serviceLocalAnnotations: serviceSettings.localAnnotationsName
249
- }, minimumUi5Version);
270
+ });
250
271
  // Add or update existing service model settings for manifest.json
251
272
  enhanceManifestModels(serviceSettings.name, serviceSettings.version, serviceSettings.model, serviceSettings.includeSynchronizationMode, manifest);
252
273
  }
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.31.12",
12
+ "version": "0.32.0",
13
13
  "license": "Apache-2.0",
14
14
  "main": "dist/index.js",
15
15
  "files": [
@@ -23,15 +23,15 @@
23
23
  "@sap-ux/edmx-parser": "0.10.0",
24
24
  "@sap-ux/annotation-converter": "0.10.21",
25
25
  "ejs": "3.1.10",
26
- "fast-xml-parser": "5.7.2",
26
+ "fast-xml-parser": "5.8.0",
27
27
  "i18next": "25.10.10",
28
28
  "mem-fs": "2.1.0",
29
29
  "mem-fs-editor": "9.4.0",
30
30
  "prettify-xml": "1.2.0",
31
31
  "semver": "7.7.4",
32
- "@sap-ux/mockserver-config-writer": "0.9.76",
33
- "@sap-ux/project-access": "1.36.3",
34
- "@sap-ux/ui5-config": "0.30.4"
32
+ "@sap-ux/mockserver-config-writer": "0.10.0",
33
+ "@sap-ux/project-access": "1.37.0",
34
+ "@sap-ux/ui5-config": "0.31.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@sap-ux/vocabularies-types": "0.15.0",
@@ -42,10 +42,10 @@
42
42
  "@types/semver": "7.7.1",
43
43
  "fs-extra": "11.3.4",
44
44
  "lodash": "4.18.1",
45
- "@sap-ux/axios-extension": "1.25.35"
45
+ "@sap-ux/axios-extension": "1.26.0"
46
46
  },
47
47
  "engines": {
48
- "node": ">=20.x"
48
+ "node": ">=22.x"
49
49
  },
50
50
  "scripts": {
51
51
  "build": "tsc --build",