@sap-ux/odata-service-writer 0.27.30 → 0.27.31
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/external-services.d.ts +29 -0
- package/dist/data/external-services.js +202 -0
- package/dist/data/index.d.ts +1 -0
- package/dist/data/index.js +1 -0
- package/dist/index.d.ts +6 -7
- package/dist/index.js +8 -4
- package/dist/types.d.ts +6 -0
- package/dist/update.js +54 -29
- package/package.json +9 -5
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Editor } from 'mem-fs-editor';
|
|
2
|
+
import type { ConvertedMetadata, RawSchema } from '@sap-ux/vocabularies-types';
|
|
3
|
+
import type { ExternalService, ExternalServiceReference } from '@sap-ux/axios-extension';
|
|
4
|
+
import type { ExternalServiceCollectionOptions } from '../types';
|
|
5
|
+
/**
|
|
6
|
+
* Writes service metadata for external service references to the local service folder.
|
|
7
|
+
*
|
|
8
|
+
* @param fs - Memfs editor instance
|
|
9
|
+
* @param webappPath - Webapp path of the UI5 application
|
|
10
|
+
* @param externalServices - External service metadata to be written
|
|
11
|
+
* @param serviceName - Name of the service, defaults to 'mainService'
|
|
12
|
+
* @param servicePath - Service path of the service
|
|
13
|
+
*/
|
|
14
|
+
export declare function writeExternalServiceMetadata(fs: Editor, webappPath: string, externalServices: ExternalService[], serviceName?: string, servicePath?: string): void;
|
|
15
|
+
/**
|
|
16
|
+
* Collects annotation values that reference external services from the given metadata and annotation files.
|
|
17
|
+
*
|
|
18
|
+
* @param serviceRootPath - The service path to which the value list references belong
|
|
19
|
+
* @param metadata - The metadata of the service
|
|
20
|
+
* @param annotations - The annotation files
|
|
21
|
+
* @param options - Options for collecting external service references.
|
|
22
|
+
* If not provided, all reference types are collected.
|
|
23
|
+
* To disable the collection of a specific type, set its value to `false`.
|
|
24
|
+
* @returns External service references found in the files.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getExternalServiceReferences(serviceRootPath: string, metadata: ConvertedMetadata | RawSchema | string | undefined, annotations?: {
|
|
27
|
+
Definitions: string;
|
|
28
|
+
}[], options?: Partial<ExternalServiceCollectionOptions>): ExternalServiceReference[];
|
|
29
|
+
//# sourceMappingURL=external-services.d.ts.map
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.writeExternalServiceMetadata = writeExternalServiceMetadata;
|
|
7
|
+
exports.getExternalServiceReferences = getExternalServiceReferences;
|
|
8
|
+
const node_path_1 = require("node:path");
|
|
9
|
+
const posix_1 = require("node:path/posix");
|
|
10
|
+
const prettify_xml_1 = __importDefault(require("prettify-xml"));
|
|
11
|
+
const annotation_converter_1 = require("@sap-ux/annotation-converter");
|
|
12
|
+
const edmx_parser_1 = require("@sap-ux/edmx-parser");
|
|
13
|
+
const project_access_1 = require("@sap-ux/project-access");
|
|
14
|
+
const constants_1 = require("./constants");
|
|
15
|
+
const INDENT_SIZE = 4;
|
|
16
|
+
/**
|
|
17
|
+
* Writes service metadata for external service references to the local service folder.
|
|
18
|
+
*
|
|
19
|
+
* @param fs - Memfs editor instance
|
|
20
|
+
* @param webappPath - Webapp path of the UI5 application
|
|
21
|
+
* @param externalServices - External service metadata to be written
|
|
22
|
+
* @param serviceName - Name of the service, defaults to 'mainService'
|
|
23
|
+
* @param servicePath - Service path of the service
|
|
24
|
+
*/
|
|
25
|
+
function writeExternalServiceMetadata(fs, webappPath, externalServices, serviceName = constants_1.DEFAULT_DATASOURCE_NAME, servicePath) {
|
|
26
|
+
if (!externalServices.length || !servicePath) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const processedServices = new Set();
|
|
30
|
+
for (const reference of externalServices) {
|
|
31
|
+
const relativeServicePath = getServiceRoot(servicePath, reference.path);
|
|
32
|
+
const filePathSegments = [webappPath, project_access_1.DirName.LocalService, serviceName, relativeServicePath];
|
|
33
|
+
const servicePathWithoutParameters = reference.path.split(';')[0];
|
|
34
|
+
if (reference.entityData && !processedServices.has(servicePathWithoutParameters)) {
|
|
35
|
+
for (const entitySetData of reference.entityData) {
|
|
36
|
+
const entityDataPath = (0, node_path_1.join)(...filePathSegments, `${entitySetData.entitySetName}.json`);
|
|
37
|
+
fs.write(entityDataPath, JSON.stringify(entitySetData.items, undefined, INDENT_SIZE));
|
|
38
|
+
}
|
|
39
|
+
processedServices.add(servicePathWithoutParameters);
|
|
40
|
+
}
|
|
41
|
+
if (reference.type === 'value-list') {
|
|
42
|
+
filePathSegments.push(reference.target);
|
|
43
|
+
}
|
|
44
|
+
filePathSegments.push('metadata.xml');
|
|
45
|
+
const path = (0, node_path_1.join)(...filePathSegments);
|
|
46
|
+
if (reference.metadata) {
|
|
47
|
+
fs.write(path, (0, prettify_xml_1.default)(reference.metadata, { indent: INDENT_SIZE }));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Builds relative service root for file system.
|
|
53
|
+
*
|
|
54
|
+
* @param mainServicePath - Path of the main service from which the external service reference originates.
|
|
55
|
+
* @param pathWithParameters - Full path of the external service reference, possibly including parameters.
|
|
56
|
+
* @returns Relative service root path.
|
|
57
|
+
*/
|
|
58
|
+
function getServiceRoot(mainServicePath, pathWithParameters) {
|
|
59
|
+
const [servicePath] = pathWithParameters.split(';');
|
|
60
|
+
const segments = servicePath.split('/');
|
|
61
|
+
let prefix = '/';
|
|
62
|
+
let currentSegment = segments.shift();
|
|
63
|
+
while (currentSegment !== undefined) {
|
|
64
|
+
const next = (0, posix_1.join)(prefix, currentSegment);
|
|
65
|
+
if (!mainServicePath.startsWith(next)) {
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
prefix = next;
|
|
69
|
+
currentSegment = segments.shift();
|
|
70
|
+
}
|
|
71
|
+
return servicePath.replace(prefix, '');
|
|
72
|
+
}
|
|
73
|
+
const DEFAULT_OPTIONS = {
|
|
74
|
+
valueListReferences: true,
|
|
75
|
+
codeLists: true
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Fills missing parameters with defaults.
|
|
79
|
+
*
|
|
80
|
+
* @param options - Options for collecting external service references
|
|
81
|
+
* @returns External service collection options with all values set.
|
|
82
|
+
*/
|
|
83
|
+
function getOptions(options) {
|
|
84
|
+
if (!options) {
|
|
85
|
+
return {
|
|
86
|
+
...DEFAULT_OPTIONS
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
valueListReferences: options.valueListReferences ?? DEFAULT_OPTIONS.valueListReferences,
|
|
91
|
+
codeLists: options.codeLists ?? DEFAULT_OPTIONS.codeLists
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Collects annotation values that reference external services from the given metadata and annotation files.
|
|
96
|
+
*
|
|
97
|
+
* @param serviceRootPath - The service path to which the value list references belong
|
|
98
|
+
* @param metadata - The metadata of the service
|
|
99
|
+
* @param annotations - The annotation files
|
|
100
|
+
* @param options - Options for collecting external service references.
|
|
101
|
+
* If not provided, all reference types are collected.
|
|
102
|
+
* To disable the collection of a specific type, set its value to `false`.
|
|
103
|
+
* @returns External service references found in the files.
|
|
104
|
+
*/
|
|
105
|
+
function getExternalServiceReferences(serviceRootPath, metadata, annotations = [], options) {
|
|
106
|
+
const finalOptions = getOptions(options);
|
|
107
|
+
if (!metadata) {
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
const files = [metadata, ...annotations.map((annotationFile) => annotationFile.Definitions)];
|
|
111
|
+
const references = [];
|
|
112
|
+
for (const data of files) {
|
|
113
|
+
const schema = typeof data === 'string' ? (0, annotation_converter_1.convert)((0, edmx_parser_1.parse)(data)) : data;
|
|
114
|
+
for (const annotationLists of Object.values(schema.annotations)) {
|
|
115
|
+
for (const annotationList of annotationLists) {
|
|
116
|
+
const target = annotationList.target.replace(schema.namespace + '.', '');
|
|
117
|
+
collectExternalServiceReferences(finalOptions, references, target, annotationList, serviceRootPath);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return references;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Collects ValueListReference values from targets annotations.
|
|
125
|
+
*
|
|
126
|
+
* @param options - Options for collecting external service references
|
|
127
|
+
* @param references - The collected value list references
|
|
128
|
+
* @param target - The target of the annotation list
|
|
129
|
+
* @param annotationList - The annotation list to be checked
|
|
130
|
+
* @param serviceRootPath - The service path to which the value list references belong
|
|
131
|
+
*/
|
|
132
|
+
function collectExternalServiceReferences(options, references, target, annotationList, serviceRootPath) {
|
|
133
|
+
for (const annotation of annotationList.annotations) {
|
|
134
|
+
collectValueListReferences(options, references, target, annotation, serviceRootPath);
|
|
135
|
+
collectCodeLists(options, references, annotation, serviceRootPath);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Collects ValueListReferences annotations.
|
|
140
|
+
*
|
|
141
|
+
* @param options - Options for collecting external service references
|
|
142
|
+
* @param references - The collected value list references
|
|
143
|
+
* @param target - The target of the annotation list
|
|
144
|
+
* @param annotation - The annotation to be checked
|
|
145
|
+
* @param serviceRootPath - The service path to which the value list references belong
|
|
146
|
+
*/
|
|
147
|
+
function collectValueListReferences(options, references, target, annotation, serviceRootPath) {
|
|
148
|
+
if (options.valueListReferences && annotation.term === 'com.sap.vocabularies.Common.v1.ValueListReferences') {
|
|
149
|
+
for (const value of annotation.collection ?? []) {
|
|
150
|
+
if (value.type === 'String') {
|
|
151
|
+
const stringValue = value;
|
|
152
|
+
references.push({
|
|
153
|
+
type: 'value-list',
|
|
154
|
+
serviceRootPath,
|
|
155
|
+
target,
|
|
156
|
+
value: stringValue.String
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Collects CodeList annotations.
|
|
164
|
+
*
|
|
165
|
+
* @param options - Options for collecting external service references
|
|
166
|
+
* @param references - The collected value list references
|
|
167
|
+
* @param annotation - The annotation to be checked
|
|
168
|
+
* @param serviceRootPath - The service path to which the value list references belong
|
|
169
|
+
*/
|
|
170
|
+
function collectCodeLists(options, references, annotation, serviceRootPath) {
|
|
171
|
+
if (options.codeLists &&
|
|
172
|
+
(annotation.term === 'com.sap.vocabularies.CodeList.v1.CurrencyCodes' ||
|
|
173
|
+
annotation.term === 'com.sap.vocabularies.CodeList.v1.UnitsOfMeasure') &&
|
|
174
|
+
annotation.record) {
|
|
175
|
+
const collectionPath = getPropertyValue(annotation.record, 'CollectionPath');
|
|
176
|
+
const url = getPropertyValue(annotation.record, 'Url');
|
|
177
|
+
if (url) {
|
|
178
|
+
references.push({
|
|
179
|
+
type: 'code-list',
|
|
180
|
+
serviceRootPath,
|
|
181
|
+
value: url,
|
|
182
|
+
collectionPath: collectionPath ?? undefined
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Reads property value from annotation record.
|
|
189
|
+
*
|
|
190
|
+
* @param record - Annotation record
|
|
191
|
+
* @param propertyName - Name of the property
|
|
192
|
+
* @returns Value of the property if it exists
|
|
193
|
+
*/
|
|
194
|
+
function getPropertyValue(record, propertyName) {
|
|
195
|
+
const property = record.propertyValues.find((prop) => prop.name === propertyName);
|
|
196
|
+
if (property?.value?.type === 'String') {
|
|
197
|
+
const value = property.value;
|
|
198
|
+
return value.String;
|
|
199
|
+
}
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=external-services.js.map
|
package/dist/data/index.d.ts
CHANGED
package/dist/data/index.js
CHANGED
|
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./defaults"), exports);
|
|
18
18
|
__exportStar(require("./annotations"), exports);
|
|
19
|
+
__exportStar(require("./external-services"), exports);
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Editor } from 'mem-fs-editor';
|
|
2
|
-
import {
|
|
3
|
-
import { OdataService, OdataVersion, ServiceType, CdsAnnotationsInfo, EdmxAnnotationsInfo, NamespaceAlias } from './types';
|
|
2
|
+
import type { OdataService } from './types';
|
|
4
3
|
/**
|
|
5
4
|
* Writes the odata service related data and files to an existing UI5 project specified by the base path.
|
|
6
5
|
*
|
|
@@ -10,7 +9,7 @@ import { OdataService, OdataVersion, ServiceType, CdsAnnotationsInfo, EdmxAnnota
|
|
|
10
9
|
* @throws {Error} - if required UI5 project files are not found
|
|
11
10
|
* @returns {Promise<Editor>} the updated memfs editor instance
|
|
12
11
|
*/
|
|
13
|
-
declare function generate(basePath: string, service: OdataService, fs?: Editor): Promise<Editor>;
|
|
12
|
+
export declare function generate(basePath: string, service: OdataService, fs?: Editor): Promise<Editor>;
|
|
14
13
|
/**
|
|
15
14
|
* Writes the odata service related file updates to an existing UI5 project specified by the base path.
|
|
16
15
|
*
|
|
@@ -21,7 +20,7 @@ declare function generate(basePath: string, service: OdataService, fs?: Editor):
|
|
|
21
20
|
* @throws {Error} - if required UI5 project files are not found
|
|
22
21
|
* @returns {Promise<Editor>} the updated memfs editor instance
|
|
23
22
|
*/
|
|
24
|
-
declare function update(basePath: string, service: OdataService, fs?: Editor, updateMiddlewares?: boolean): Promise<Editor>;
|
|
23
|
+
export declare function update(basePath: string, service: OdataService, fs?: Editor, updateMiddlewares?: boolean): Promise<Editor>;
|
|
25
24
|
/**
|
|
26
25
|
* Removes service related data from project files for an existing UI5 project specified by the base path.
|
|
27
26
|
* How the method works:
|
|
@@ -48,7 +47,7 @@ declare function update(basePath: string, service: OdataService, fs?: Editor, up
|
|
|
48
47
|
* @throws {Error} - if required UI5 project files are not found
|
|
49
48
|
* @returns {Promise<Editor>} the updated memfs editor instance
|
|
50
49
|
*/
|
|
51
|
-
declare function remove(basePath: string, service: OdataService, fs?: Editor): Promise<Editor>;
|
|
52
|
-
export {
|
|
53
|
-
export { getAnnotationNamespaces,
|
|
50
|
+
export declare function remove(basePath: string, service: OdataService, fs?: Editor): Promise<Editor>;
|
|
51
|
+
export { OdataVersion, OdataService, ServiceType, EdmxAnnotationsInfo, CdsAnnotationsInfo, ExternalServiceCollectionOptions, NamespaceAlias } from './types';
|
|
52
|
+
export { getExternalServiceReferences, getAnnotationNamespaces, writeExternalServiceMetadata } from './data';
|
|
54
53
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAnnotationNamespaces = exports.ServiceType = exports.OdataVersion = void 0;
|
|
3
|
+
exports.writeExternalServiceMetadata = exports.getAnnotationNamespaces = exports.getExternalServiceReferences = exports.ServiceType = exports.OdataVersion = void 0;
|
|
4
4
|
exports.generate = generate;
|
|
5
5
|
exports.update = update;
|
|
6
6
|
exports.remove = remove;
|
|
@@ -9,11 +9,8 @@ const mem_fs_1 = require("mem-fs");
|
|
|
9
9
|
const mem_fs_editor_1 = require("mem-fs-editor");
|
|
10
10
|
const update_1 = require("./update");
|
|
11
11
|
const data_1 = require("./data");
|
|
12
|
-
Object.defineProperty(exports, "getAnnotationNamespaces", { enumerable: true, get: function () { return data_1.getAnnotationNamespaces; } });
|
|
13
12
|
const i18n_1 = require("./i18n");
|
|
14
13
|
const types_1 = require("./types");
|
|
15
|
-
Object.defineProperty(exports, "OdataVersion", { enumerable: true, get: function () { return types_1.OdataVersion; } });
|
|
16
|
-
Object.defineProperty(exports, "ServiceType", { enumerable: true, get: function () { return types_1.ServiceType; } });
|
|
17
14
|
const delete_1 = require("./delete");
|
|
18
15
|
const project_access_1 = require("@sap-ux/project-access");
|
|
19
16
|
const manifest_1 = require("./data/manifest");
|
|
@@ -160,4 +157,11 @@ async function remove(basePath, service, fs) {
|
|
|
160
157
|
}
|
|
161
158
|
return fs;
|
|
162
159
|
}
|
|
160
|
+
var types_2 = require("./types");
|
|
161
|
+
Object.defineProperty(exports, "OdataVersion", { enumerable: true, get: function () { return types_2.OdataVersion; } });
|
|
162
|
+
Object.defineProperty(exports, "ServiceType", { enumerable: true, get: function () { return types_2.ServiceType; } });
|
|
163
|
+
var data_2 = require("./data");
|
|
164
|
+
Object.defineProperty(exports, "getExternalServiceReferences", { enumerable: true, get: function () { return data_2.getExternalServiceReferences; } });
|
|
165
|
+
Object.defineProperty(exports, "getAnnotationNamespaces", { enumerable: true, get: function () { return data_2.getAnnotationNamespaces; } });
|
|
166
|
+
Object.defineProperty(exports, "writeExternalServiceMetadata", { enumerable: true, get: function () { return data_2.writeExternalServiceMetadata; } });
|
|
163
167
|
//# sourceMappingURL=index.js.map
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { ManifestNamespace } from '@sap-ux/project-access';
|
|
2
2
|
import type { FioriToolsProxyConfigBackend as ProxyBackend } from '@sap-ux/ui5-config';
|
|
3
|
+
import type { ExternalService } from '@sap-ux/axios-extension';
|
|
4
|
+
export interface ExternalServiceCollectionOptions {
|
|
5
|
+
valueListReferences: boolean;
|
|
6
|
+
codeLists: boolean;
|
|
7
|
+
}
|
|
3
8
|
export declare enum OdataVersion {
|
|
4
9
|
v2 = "2",
|
|
5
10
|
v4 = "4"
|
|
@@ -63,6 +68,7 @@ export interface OdataService {
|
|
|
63
68
|
name?: string;
|
|
64
69
|
model?: string;
|
|
65
70
|
metadata?: string;
|
|
71
|
+
externalServices?: ExternalService[];
|
|
66
72
|
/**
|
|
67
73
|
* Annotations can either be EDMX annotations or CDS annotations.
|
|
68
74
|
*/
|
package/dist/update.js
CHANGED
|
@@ -8,6 +8,7 @@ const ui5_config_1 = require("@sap-ux/ui5-config");
|
|
|
8
8
|
const mockserver_config_writer_1 = require("@sap-ux/mockserver-config-writer");
|
|
9
9
|
const annotations_1 = require("./data/annotations");
|
|
10
10
|
const package_1 = require("./data/package");
|
|
11
|
+
const data_1 = require("./data");
|
|
11
12
|
/**
|
|
12
13
|
* Generates mockserver middleware config for ui5-local.yaml file based on ui5-mock.yaml.
|
|
13
14
|
*
|
|
@@ -126,7 +127,6 @@ async function addServicesData(basePath, paths, templateRoot, service, fs) {
|
|
|
126
127
|
async function updateServicesData(basePath, paths, service, fs, updateMiddlewares) {
|
|
127
128
|
let ui5Config;
|
|
128
129
|
let ui5LocalConfig;
|
|
129
|
-
let ui5MockConfig;
|
|
130
130
|
if (updateMiddlewares) {
|
|
131
131
|
if (paths.ui5Yaml) {
|
|
132
132
|
ui5Config = await ui5_config_1.UI5Config.newInstance(fs.read(paths.ui5Yaml));
|
|
@@ -140,39 +140,64 @@ async function updateServicesData(basePath, paths, service, fs, updateMiddleware
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
// For update, updatable files should already exist
|
|
143
|
-
|
|
144
|
-
const webappPath = await (0, project_access_1.getWebappPath)(basePath, fs);
|
|
145
|
-
// Generate mockserver only when ui5-mock.yaml already exists
|
|
146
|
-
if (paths.ui5MockYaml && paths.ui5Yaml && ui5Config && updateMiddlewares) {
|
|
147
|
-
const config = {
|
|
148
|
-
webappPath: webappPath,
|
|
149
|
-
// Since ui5-mock.yaml already exists, set 'skip' to skip package.json file updates
|
|
150
|
-
packageJsonConfig: {
|
|
151
|
-
skip: true
|
|
152
|
-
},
|
|
153
|
-
// Set 'overwrite' to true to overwrite services data in YAML files
|
|
154
|
-
ui5MockYamlConfig: {
|
|
155
|
-
overwrite: true
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
// Regenerate mockserver middleware for ui5-mock.yaml by overwriting
|
|
159
|
-
await (0, mockserver_config_writer_1.generateMockserverConfig)(basePath, config, fs);
|
|
160
|
-
// Update ui5-local.yaml with mockserver middleware from updated ui5-mock.yaml
|
|
161
|
-
await generateMockserverMiddlewareBasedOnUi5MockYaml(fs, paths.ui5Yaml, paths.ui5LocalYaml, ui5LocalConfig);
|
|
162
|
-
// Update ui5-mock.yaml with backend middleware
|
|
163
|
-
if (paths.ui5MockYaml) {
|
|
164
|
-
ui5MockConfig = await ui5_config_1.UI5Config.newInstance(fs.read(paths.ui5MockYaml));
|
|
165
|
-
extendBackendMiddleware(fs, service, ui5MockConfig, paths.ui5MockYaml, true);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
// Write metadata.xml file
|
|
169
|
-
await (0, annotations_1.writeMetadata)(fs, webappPath, service);
|
|
170
|
-
}
|
|
143
|
+
const webappPath = await updateMetadata(basePath, paths, service, ui5Config, ui5LocalConfig, fs, updateMiddlewares);
|
|
171
144
|
if (paths.ui5LocalYaml && ui5LocalConfig) {
|
|
172
145
|
// write ui5 local yaml if service type is not CDS
|
|
173
146
|
fs.write(paths.ui5LocalYaml, ui5LocalConfig.toString());
|
|
174
147
|
}
|
|
175
148
|
// Write new annotations files
|
|
176
149
|
await (0, annotations_1.writeRemoteServiceAnnotationXmlFiles)(fs, basePath, service.name ?? 'mainService', service.annotations);
|
|
150
|
+
if (service.externalServices && webappPath) {
|
|
151
|
+
(0, data_1.writeExternalServiceMetadata)(fs, webappPath, service.externalServices, service.name, service.path);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Updates metadata related data for the given service in the project files.
|
|
156
|
+
*
|
|
157
|
+
* @param {string} basePath - the root path of an existing UI5 application
|
|
158
|
+
* @param {ProjectPaths} paths - paths to the project files (package.json, ui5.yaml, ui5-local.yaml and ui5-mock.yaml)
|
|
159
|
+
* @param {EdmxOdataService} service - the OData service instance
|
|
160
|
+
* @param {UI5Config | undefined} ui5Config - ui5.yaml configuration
|
|
161
|
+
* @param {UI5Config | undefined} ui5LocalConfig - ui5-local.yaml configuration
|
|
162
|
+
* @param {Editor} fs - the memfs editor instance
|
|
163
|
+
* @param {boolean} updateMiddlewares - whether the YAML files for the service (mock-server and fiori-tools-proxy middlewares) should be updated
|
|
164
|
+
* @returns {Promise<string | undefined>} webapp path if metadata was written, undefined otherwise
|
|
165
|
+
*/
|
|
166
|
+
async function updateMetadata(basePath, paths, service, ui5Config, ui5LocalConfig, fs, updateMiddlewares) {
|
|
167
|
+
if (!service.metadata) {
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
const webappPath = await (0, project_access_1.getWebappPath)(basePath, fs);
|
|
171
|
+
// Generate mockserver only when ui5-mock.yaml already exists
|
|
172
|
+
if (paths.ui5MockYaml && paths.ui5Yaml && ui5Config && updateMiddlewares) {
|
|
173
|
+
const config = {
|
|
174
|
+
webappPath: webappPath,
|
|
175
|
+
// Since ui5-mock.yaml already exists, set 'skip' to skip package.json file updates
|
|
176
|
+
packageJsonConfig: {
|
|
177
|
+
skip: true
|
|
178
|
+
},
|
|
179
|
+
// Set 'overwrite' to true to overwrite services data in YAML files
|
|
180
|
+
ui5MockYamlConfig: {
|
|
181
|
+
overwrite: true
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
if (config.ui5MockYamlConfig && service.name && service.externalServices?.length) {
|
|
185
|
+
config.ui5MockYamlConfig.resolveExternalServiceReferences = {
|
|
186
|
+
[service.name]: true
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
// Regenerate mockserver middleware for ui5-mock.yaml by overwriting
|
|
190
|
+
await (0, mockserver_config_writer_1.generateMockserverConfig)(basePath, config, fs);
|
|
191
|
+
// Update ui5-local.yaml with mockserver middleware from updated ui5-mock.yaml
|
|
192
|
+
await generateMockserverMiddlewareBasedOnUi5MockYaml(fs, paths.ui5Yaml, paths.ui5LocalYaml, ui5LocalConfig);
|
|
193
|
+
// Update ui5-mock.yaml with backend middleware
|
|
194
|
+
if (paths.ui5MockYaml) {
|
|
195
|
+
const ui5MockConfig = await ui5_config_1.UI5Config.newInstance(fs.read(paths.ui5MockYaml));
|
|
196
|
+
extendBackendMiddleware(fs, service, ui5MockConfig, paths.ui5MockYaml, true);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
// Write metadata.xml file
|
|
200
|
+
await (0, annotations_1.writeMetadata)(fs, webappPath, service);
|
|
201
|
+
return webappPath;
|
|
177
202
|
}
|
|
178
203
|
//# sourceMappingURL=update.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.27.
|
|
12
|
+
"version": "0.27.31",
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"main": "dist/index.js",
|
|
15
15
|
"files": [
|
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
"!dist/**/*.map"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
+
"@sap-ux/edmx-parser": "0.9.1",
|
|
24
|
+
"@sap-ux/annotation-converter": "0.10.8",
|
|
23
25
|
"ejs": "3.1.10",
|
|
24
26
|
"fast-xml-parser": "4.4.1",
|
|
25
27
|
"i18next": "25.3.0",
|
|
@@ -27,18 +29,20 @@
|
|
|
27
29
|
"mem-fs-editor": "9.4.0",
|
|
28
30
|
"prettify-xml": "1.2.0",
|
|
29
31
|
"semver": "7.5.4",
|
|
30
|
-
"@sap-ux/mockserver-config-writer": "0.9.
|
|
31
|
-
"@sap-ux/project-access": "1.32.
|
|
32
|
-
"@sap-ux/ui5-config": "0.29.
|
|
32
|
+
"@sap-ux/mockserver-config-writer": "0.9.27",
|
|
33
|
+
"@sap-ux/project-access": "1.32.10",
|
|
34
|
+
"@sap-ux/ui5-config": "0.29.10"
|
|
33
35
|
},
|
|
34
36
|
"devDependencies": {
|
|
37
|
+
"@sap-ux/vocabularies-types": "0.13.1",
|
|
35
38
|
"@types/ejs": "3.1.2",
|
|
36
39
|
"@types/fs-extra": "9.0.13",
|
|
37
40
|
"@types/mem-fs": "1.1.2",
|
|
38
41
|
"@types/mem-fs-editor": "7.0.1",
|
|
39
42
|
"@types/semver": "7.5.2",
|
|
40
43
|
"fs-extra": "10.0.0",
|
|
41
|
-
"lodash": "4.17.21"
|
|
44
|
+
"lodash": "4.17.21",
|
|
45
|
+
"@sap-ux/axios-extension": "1.24.3"
|
|
42
46
|
},
|
|
43
47
|
"engines": {
|
|
44
48
|
"node": ">=20.x"
|