@sap-ux/odata-service-writer 0.21.1 → 0.22.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.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.enhanceData = void 0;
4
- const updates_1 = require("../updates");
4
+ const types_1 = require("../types");
5
5
  const constants_1 = require("./constants");
6
6
  /**
7
7
  * Sets the default path for a given service.
@@ -39,13 +39,6 @@ function setDefaultServiceModel(service) {
39
39
  * @param {OdataService} service - The service object whose annotations name needs to be set or modified.
40
40
  */
41
41
  function setDefaultAnnotationsName(service) {
42
- /**
43
- * In the manifest EJS template, annotation names are referred to for adding annotations to the manifest.json.
44
- * For CAP projects, annotations are added to the annotations.cds file and not to the manifest.json.
45
- */
46
- if ((0, updates_1.serviceIsCds)(service)) {
47
- return;
48
- }
49
42
  const annotations = service.annotations;
50
43
  if (annotations?.technicalName && !annotations.name) {
51
44
  annotations.name = annotations?.technicalName?.replace(/\//g, '_')?.replace(/^_/, '');
@@ -61,7 +54,16 @@ function enhanceData(service) {
61
54
  setDefaultServicePath(service);
62
55
  setDefaultServiceName(service);
63
56
  setDefaultServiceModel(service);
64
- setDefaultAnnotationsName(service);
57
+ // set service type to EDMX if not defined
58
+ service.type = service.type ?? types_1.ServiceType.EDMX;
59
+ /**
60
+ * In the manifest EJS template, annotation names are used to add annotations to the manifest.json.
61
+ * For CAP projects, annotations are added to the annotations.cds file instead of the manifest.json.
62
+ * If the service type is EDMX, this function sets the default annotation names to be included in the manifest.json.
63
+ */
64
+ if (service.type === types_1.ServiceType.EDMX) {
65
+ setDefaultAnnotationsName(service);
66
+ }
65
67
  // enhance preview settings with service configuration
66
68
  service.previewSettings = service.previewSettings || {};
67
69
  service.previewSettings.path =
package/dist/index.js CHANGED
@@ -70,10 +70,12 @@ async function generate(basePath, service, fs) {
70
70
  const paths = await findProjectFiles(basePath, fs);
71
71
  ensureExists(basePath, ['webapp/manifest.json'], fs);
72
72
  (0, data_1.enhanceData)(service);
73
+ // set isServiceTypeEdmx true if service is EDMX
74
+ const isServiceTypeEdmx = service.type === types_1.ServiceType.EDMX;
73
75
  // merge content into existing files
74
76
  const templateRoot = (0, path_1.join)(__dirname, '../templates');
75
77
  // update cds files with annotations only if service type is CDS and annotations are provided
76
- if ((0, updates_1.serviceIsCds)(service) && service.annotations) {
78
+ if (!isServiceTypeEdmx && service.annotations) {
77
79
  await (0, updates_1.updateCdsFilesWithAnnotations)(service.annotations, fs);
78
80
  }
79
81
  // manifest.json
@@ -82,8 +84,8 @@ async function generate(basePath, service, fs) {
82
84
  let ui5Config;
83
85
  let ui5LocalConfig;
84
86
  let ui5LocalConfigPath;
85
- if (!(0, updates_1.serviceIsCds)(service) && paths.ui5Yaml) {
86
- // Dont extend backend middlewares if service type is CDS
87
+ if (isServiceTypeEdmx && paths.ui5Yaml) {
88
+ // Dont extend backend middlewares if service type is CDS.
87
89
  ui5Config = await ui5_config_1.UI5Config.newInstance(fs.read(paths.ui5Yaml));
88
90
  try {
89
91
  ui5Config.addBackendToFioriToolsProxydMiddleware(service.previewSettings);
@@ -105,7 +107,7 @@ async function generate(basePath, service, fs) {
105
107
  }
106
108
  }
107
109
  // Add mockserver entries
108
- if (!(0, updates_1.serviceIsCds)(service) && service.metadata) {
110
+ if (isServiceTypeEdmx && service.metadata) {
109
111
  // mockserver entries are not required if service type is CDS
110
112
  // copy existing `ui5.yaml` as starting point for ui5-mock.yaml
111
113
  if (paths.ui5Yaml && ui5Config) {
@@ -128,15 +130,18 @@ async function generate(basePath, service, fs) {
128
130
  fs.copyTpl((0, path_1.join)(templateRoot, 'add', 'annotation.xml'), (0, path_1.join)(basePath, 'webapp', 'annotations', `${service.localAnnotationsName}.xml`), { ...service, namespaces });
129
131
  }
130
132
  }
131
- // update package.json if required
132
- if (paths.packageJson && paths.ui5Yaml) {
133
+ // update package.json for non-cap applications
134
+ if (isServiceTypeEdmx && paths.packageJson && paths.ui5Yaml) {
133
135
  (0, updates_1.updatePackageJson)(paths.packageJson, fs, !!service.metadata);
134
136
  }
135
- if (ui5LocalConfigPath && ui5LocalConfig) {
137
+ if (isServiceTypeEdmx && ui5LocalConfigPath && ui5LocalConfig) {
138
+ // write ui5 local yaml if service type is not CDS
136
139
  fs.write(ui5LocalConfigPath, ui5LocalConfig.toString());
137
140
  }
138
141
  // Write annotation xml if annotations are provided and service type is EDMX
139
- (0, updates_1.writeAnnotationXmlFiles)(fs, basePath, service);
142
+ if (isServiceTypeEdmx) {
143
+ (0, updates_1.writeAnnotationXmlFiles)(fs, basePath, service);
144
+ }
140
145
  return fs;
141
146
  }
142
147
  exports.generate = generate;
package/dist/updates.d.ts CHANGED
@@ -1,12 +1,5 @@
1
1
  import type { Editor } from 'mem-fs-editor';
2
2
  import type { OdataService, CdsAnnotationsInfo } from './types';
3
- /**
4
- * Function to check if the service type is CDS.
5
- *
6
- * @param service - the OData service instance
7
- * @returns true if the service type is CDS
8
- */
9
- export declare function serviceIsCds(service: OdataService): boolean;
10
3
  /**
11
4
  * Internal function that updates the manifest.json based on the given service configuration.
12
5
  *
package/dist/updates.js CHANGED
@@ -26,29 +26,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.hasUI5CliV3 = exports.updatePackageJson = exports.updateCdsFilesWithAnnotations = exports.writeAnnotationXmlFiles = exports.updateManifest = exports.serviceIsCds = void 0;
29
+ exports.hasUI5CliV3 = exports.updatePackageJson = exports.updateCdsFilesWithAnnotations = exports.writeAnnotationXmlFiles = exports.updateManifest = void 0;
30
30
  const ejs_1 = require("ejs");
31
31
  const path_1 = __importStar(require("path"));
32
32
  const i18n_1 = require("./i18n");
33
- const types_1 = require("./types");
34
33
  const semver_1 = __importDefault(require("semver"));
35
34
  const prettify_xml_1 = __importDefault(require("prettify-xml"));
36
- /**
37
- * Function to check if the service type is CDS.
38
- *
39
- * @param service - the OData service instance
40
- * @returns true if the service type is CDS
41
- */
42
- function serviceIsCds(service) {
43
- // if service type is not defined, set EDMX as default
44
- let serviceType = service.type;
45
- serviceType ||= types_1.ServiceType.EDMX;
46
- if (serviceType === types_1.ServiceType.CDS) {
47
- return true;
48
- }
49
- return false;
50
- }
51
- exports.serviceIsCds = serviceIsCds;
52
35
  /**
53
36
  * Internal function that updates the manifest.json based on the given service configuration.
54
37
  *
@@ -110,9 +93,6 @@ async function updateCdsIndexOrServiceFile(fs, annotations) {
110
93
  * @param {OdataService} service - The OData service information.
111
94
  */
112
95
  function writeAnnotationXmlFiles(fs, basePath, service) {
113
- if (serviceIsCds(service)) {
114
- return;
115
- }
116
96
  // Write annotation xml if annotations are provided and service type is EDMX
117
97
  const annotations = service.annotations;
118
98
  if (annotations?.xml) {
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.21.1",
12
+ "version": "0.22.0",
13
13
  "license": "Apache-2.0",
14
14
  "main": "dist/index.js",
15
15
  "files": [
@@ -38,7 +38,7 @@
38
38
  "@types/semver": "7.5.2",
39
39
  "fs-extra": "10.0.0",
40
40
  "lodash": "4.17.21",
41
- "@sap-ux/project-access": "1.25.3"
41
+ "@sap-ux/project-access": "1.25.4"
42
42
  },
43
43
  "engines": {
44
44
  "node": ">=18.x"