@sap-ux/odata-service-writer 0.25.9 → 0.26.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.
- package/dist/data/annotations.d.ts +50 -1
- package/dist/data/annotations.js +200 -0
- package/dist/data/manifest.d.ts +20 -0
- package/dist/data/manifest.js +423 -0
- package/dist/data/package.d.ts +10 -0
- package/dist/data/package.js +38 -0
- package/dist/delete.d.ts +5 -23
- package/dist/delete.js +50 -164
- package/dist/index.d.ts +10 -9
- package/dist/index.js +39 -181
- package/dist/update.d.ts +26 -0
- package/dist/update.js +158 -0
- package/package.json +3 -3
- package/dist/updates.d.ts +0 -38
- package/dist/updates.js +0 -375
|
@@ -1,4 +1,53 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Editor } from 'mem-fs-editor';
|
|
2
|
+
import type { NamespaceAlias, OdataService, EdmxAnnotationsInfo, EdmxOdataService, CdsAnnotationsInfo } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Updates cds files with the provided annotations.
|
|
5
|
+
* This function takes cds annotations and an Editor instance,
|
|
6
|
+
* then updates the relevant cds files with the given annotations.
|
|
7
|
+
*
|
|
8
|
+
* @param {CdsAnnotationsInfo} annotations - The cds annotations info.
|
|
9
|
+
* @param {Editor} fs - The memfs editor instance
|
|
10
|
+
* @returns {Promise<void>} A promise that resolves when the cds files have been updated.
|
|
11
|
+
*/
|
|
12
|
+
export declare function updateCdsFilesWithAnnotations(annotations: CdsAnnotationsInfo | CdsAnnotationsInfo[], fs: Editor): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Removes annotations from CDS files.
|
|
15
|
+
* This function takes cds annotations and an Editor instance,
|
|
16
|
+
* then updates the relevant cds files with the given annotations.
|
|
17
|
+
*
|
|
18
|
+
* @param {CdsAnnotationsInfo} annotations - The cds annotations info.
|
|
19
|
+
* @param {Editor} fs - The memfs editor instance
|
|
20
|
+
* @returns {Promise<void>} A promise that resolves when the cds files have been updated.
|
|
21
|
+
*/
|
|
22
|
+
export declare function removeAnnotationsFromCDSFiles(annotations: CdsAnnotationsInfo | CdsAnnotationsInfo[], fs: Editor): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Writes local copies of metadata.xml and local annotations.
|
|
25
|
+
*
|
|
26
|
+
* @param {Editor} fs - the memfs editor instance
|
|
27
|
+
* @param {string} basePath - the root path of an existing UI5 application
|
|
28
|
+
* @param {string} webappPath - the webapp path of an existing UI5 application
|
|
29
|
+
* @param {string} templateRoot - path to the file templates
|
|
30
|
+
* @param {OdataService} service - the OData service instance with EDMX type
|
|
31
|
+
*/
|
|
32
|
+
export declare function writeLocalServiceAnnotationXMLFiles(fs: Editor, basePath: string, webappPath: string, templateRoot: string, service: EdmxOdataService): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Removes annotation XML files for EDMX annotations.
|
|
35
|
+
*
|
|
36
|
+
* @param {Editor} fs - The memfs editor instance.
|
|
37
|
+
* @param {string} basePath - The base path of the project.
|
|
38
|
+
* @param {string} serviceName - Name of The OData service.
|
|
39
|
+
* @param {OdataService} edmxAnnotations - The OData service annotations.
|
|
40
|
+
*/
|
|
41
|
+
export declare function removeRemoteServiceAnnotationXmlFiles(fs: Editor, basePath: string, serviceName: string, edmxAnnotations: EdmxAnnotationsInfo | EdmxAnnotationsInfo[]): void;
|
|
42
|
+
/**
|
|
43
|
+
* Writes annotation XML files for EDMX service annotations.
|
|
44
|
+
*
|
|
45
|
+
* @param {Editor} fs - The memfs editor instance.
|
|
46
|
+
* @param {string} basePath - The base path of the project.
|
|
47
|
+
* @param {string} serviceName - Name of The OData service.
|
|
48
|
+
* @param {OdataService} edmxAnnotations - The OData service annotations.
|
|
49
|
+
*/
|
|
50
|
+
export declare function writeRemoteServiceAnnotationXmlFiles(fs: Editor, basePath: string, serviceName: string, edmxAnnotations: EdmxAnnotationsInfo | EdmxAnnotationsInfo[]): void;
|
|
2
51
|
/**
|
|
3
52
|
* Returns the namespaces parsed from the specified metadata and annotations.
|
|
4
53
|
*
|
package/dist/data/annotations.js
CHANGED
|
@@ -1,8 +1,208 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.updateCdsFilesWithAnnotations = updateCdsFilesWithAnnotations;
|
|
7
|
+
exports.removeAnnotationsFromCDSFiles = removeAnnotationsFromCDSFiles;
|
|
8
|
+
exports.writeLocalServiceAnnotationXMLFiles = writeLocalServiceAnnotationXMLFiles;
|
|
9
|
+
exports.removeRemoteServiceAnnotationXmlFiles = removeRemoteServiceAnnotationXmlFiles;
|
|
10
|
+
exports.writeRemoteServiceAnnotationXmlFiles = writeRemoteServiceAnnotationXmlFiles;
|
|
3
11
|
exports.getAnnotationNamespaces = getAnnotationNamespaces;
|
|
12
|
+
const path_1 = require("path");
|
|
4
13
|
const fast_xml_parser_1 = require("fast-xml-parser");
|
|
5
14
|
const i18n_1 = require("../i18n");
|
|
15
|
+
const prettify_xml_1 = __importDefault(require("prettify-xml"));
|
|
16
|
+
/**
|
|
17
|
+
* Updates the cds index or service file with the provided annotations.
|
|
18
|
+
* This function takes an Editor instance and cds annotations
|
|
19
|
+
* and updates either the index file or the service file with the given annotations.
|
|
20
|
+
*
|
|
21
|
+
* @param {Editor} fs - The memfs editor instance
|
|
22
|
+
* @param {CdsAnnotationsInfo} annotations - The cds annotations info.
|
|
23
|
+
* @returns {Promise<void>} A promise that resolves when the cds files have been updated.
|
|
24
|
+
*/
|
|
25
|
+
async function updateCdsIndexOrServiceFile(fs, annotations) {
|
|
26
|
+
const dirPath = (0, path_1.join)(annotations.projectName, 'annotations');
|
|
27
|
+
const annotationPath = (0, path_1.normalize)(dirPath).split(/[\\/]/g).join(path_1.posix.sep);
|
|
28
|
+
const annotationConfig = `\nusing from './${annotationPath}';`;
|
|
29
|
+
// get index and service file paths
|
|
30
|
+
const indexFilePath = (0, path_1.join)(annotations.projectPath, annotations.appPath ?? '', 'index.cds');
|
|
31
|
+
const serviceFilePath = (0, path_1.join)(annotations.projectPath, annotations.appPath ?? '', 'services.cds');
|
|
32
|
+
// extend index or service file with annotation config
|
|
33
|
+
if (indexFilePath && fs.exists(indexFilePath)) {
|
|
34
|
+
fs.append(indexFilePath, annotationConfig);
|
|
35
|
+
}
|
|
36
|
+
else if (fs.exists(serviceFilePath)) {
|
|
37
|
+
fs.append(serviceFilePath, annotationConfig);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
fs.write(serviceFilePath, annotationConfig);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Updates cds files with the provided annotations.
|
|
45
|
+
* This function takes cds annotations and an Editor instance,
|
|
46
|
+
* then updates the relevant cds files with the given annotations.
|
|
47
|
+
*
|
|
48
|
+
* @param {CdsAnnotationsInfo} annotations - The cds annotations info.
|
|
49
|
+
* @param {Editor} fs - The memfs editor instance
|
|
50
|
+
* @returns {Promise<void>} A promise that resolves when the cds files have been updated.
|
|
51
|
+
*/
|
|
52
|
+
async function updateCdsFilesWithAnnotations(annotations, fs) {
|
|
53
|
+
if (Array.isArray(annotations)) {
|
|
54
|
+
for (const annotationName in annotations) {
|
|
55
|
+
const annotation = annotations[annotationName];
|
|
56
|
+
const annotationCdsPath = (0, path_1.join)(annotation.projectPath, annotation.appPath ?? '', annotation.projectName, 'annotations.cds');
|
|
57
|
+
// write into annotations.cds file
|
|
58
|
+
if (fs.exists(annotationCdsPath)) {
|
|
59
|
+
fs.append(annotationCdsPath, annotation.cdsFileContents);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
fs.write(annotationCdsPath, annotation.cdsFileContents);
|
|
63
|
+
}
|
|
64
|
+
await updateCdsIndexOrServiceFile(fs, annotation);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const annotationCdsPath = (0, path_1.join)(annotations.projectPath, annotations.appPath ?? '', annotations.projectName, 'annotations.cds');
|
|
69
|
+
// write into annotations.cds file
|
|
70
|
+
fs.write(annotationCdsPath, annotations.cdsFileContents);
|
|
71
|
+
await updateCdsIndexOrServiceFile(fs, annotations);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Removes the cds index or service file with the provided annotations.
|
|
76
|
+
* This function takes an Editor instance and cds annotations
|
|
77
|
+
* and deletes either from the index file or the service file with the given annotations.
|
|
78
|
+
*
|
|
79
|
+
* @param {Editor} fs - The memfs editor instance
|
|
80
|
+
* @param {CdsAnnotationsInfo} annotations - The cds annotations info.
|
|
81
|
+
* @returns {Promise<void>} A promise that resolves when the cds files have been updated.
|
|
82
|
+
*/
|
|
83
|
+
async function removeCdsIndexOrServiceFile(fs, annotations) {
|
|
84
|
+
const dirPath = (0, path_1.join)(annotations.projectName, 'annotations');
|
|
85
|
+
const annotationPath = (0, path_1.normalize)(dirPath).split(/[\\/]/g).join(path_1.posix.sep);
|
|
86
|
+
const annotationConfig = `\nusing from './${annotationPath}';`;
|
|
87
|
+
// Get index and service file paths
|
|
88
|
+
const indexFilePath = (0, path_1.join)(annotations.projectPath, annotations.appPath ?? '', 'index.cds');
|
|
89
|
+
const serviceFilePath = (0, path_1.join)(annotations.projectPath, annotations.appPath ?? '', 'services.cds');
|
|
90
|
+
// Remove annotation config from index or service file
|
|
91
|
+
if (indexFilePath && fs.exists(indexFilePath)) {
|
|
92
|
+
// Read old annotations content and replace it with empty string
|
|
93
|
+
const initialIndexContent = fs.read(indexFilePath);
|
|
94
|
+
const updatedContent = initialIndexContent.replace(annotationConfig, '');
|
|
95
|
+
fs.write(indexFilePath, updatedContent);
|
|
96
|
+
}
|
|
97
|
+
else if (fs.exists(serviceFilePath)) {
|
|
98
|
+
// Read old annotations content and replace it with empty string
|
|
99
|
+
const initialServiceFileContent = fs.read(serviceFilePath);
|
|
100
|
+
const updatedContent = initialServiceFileContent.replace(annotationConfig, '');
|
|
101
|
+
fs.write(serviceFilePath, updatedContent);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Removes annotations from CDS files.
|
|
106
|
+
* This function takes cds annotations and an Editor instance,
|
|
107
|
+
* then updates the relevant cds files with the given annotations.
|
|
108
|
+
*
|
|
109
|
+
* @param {CdsAnnotationsInfo} annotations - The cds annotations info.
|
|
110
|
+
* @param {Editor} fs - The memfs editor instance
|
|
111
|
+
* @returns {Promise<void>} A promise that resolves when the cds files have been updated.
|
|
112
|
+
*/
|
|
113
|
+
async function removeAnnotationsFromCDSFiles(annotations, fs) {
|
|
114
|
+
if (Array.isArray(annotations)) {
|
|
115
|
+
for (const annotationName in annotations) {
|
|
116
|
+
const annotation = annotations[annotationName];
|
|
117
|
+
const annotationCdsPath = (0, path_1.join)(annotation.projectPath, annotation.appPath ?? '', annotation.projectName, 'annotations.cds');
|
|
118
|
+
// Remove from annotations.cds file
|
|
119
|
+
if (fs.exists(annotationCdsPath)) {
|
|
120
|
+
// Read old annotations content and replace it with empty string
|
|
121
|
+
const initialCDSContent = fs.read(annotationCdsPath);
|
|
122
|
+
const updatedContent = initialCDSContent.replace(annotation.cdsFileContents, '');
|
|
123
|
+
fs.write(annotationCdsPath, updatedContent);
|
|
124
|
+
}
|
|
125
|
+
await removeCdsIndexOrServiceFile(fs, annotation);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
const annotationCdsPath = (0, path_1.join)(annotations.projectPath, annotations.appPath ?? '', annotations.projectName, 'annotations.cds');
|
|
130
|
+
// Write into annotations.cds file
|
|
131
|
+
if (fs.exists(annotationCdsPath)) {
|
|
132
|
+
// Read old annotations content and replace it with empty string
|
|
133
|
+
const initialCDSContent = fs.read(annotationCdsPath);
|
|
134
|
+
const updatedContent = initialCDSContent.replace(annotations.cdsFileContents, '');
|
|
135
|
+
fs.write(annotationCdsPath, updatedContent);
|
|
136
|
+
}
|
|
137
|
+
await removeCdsIndexOrServiceFile(fs, annotations);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Writes local copies of metadata.xml and local annotations.
|
|
142
|
+
*
|
|
143
|
+
* @param {Editor} fs - the memfs editor instance
|
|
144
|
+
* @param {string} basePath - the root path of an existing UI5 application
|
|
145
|
+
* @param {string} webappPath - the webapp path of an existing UI5 application
|
|
146
|
+
* @param {string} templateRoot - path to the file templates
|
|
147
|
+
* @param {OdataService} service - the OData service instance with EDMX type
|
|
148
|
+
*/
|
|
149
|
+
async function writeLocalServiceAnnotationXMLFiles(fs, basePath, webappPath, templateRoot, service) {
|
|
150
|
+
// mainService should be used in case there is no name defined for service
|
|
151
|
+
fs.write((0, path_1.join)(webappPath, 'localService', service.name ?? 'mainService', 'metadata.xml'), (0, prettify_xml_1.default)(service.metadata, { indent: 4 }));
|
|
152
|
+
// Adds local annotations to datasources section of manifest.json and writes the annotations file
|
|
153
|
+
if (service.localAnnotationsName) {
|
|
154
|
+
const namespaces = getAnnotationNamespaces(service);
|
|
155
|
+
fs.copyTpl((0, path_1.join)(templateRoot, 'add', 'annotation.xml'), (0, path_1.join)(basePath, 'webapp', 'annotations', `${service.localAnnotationsName}.xml`), { ...service, namespaces });
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Removes annotation XML files for EDMX annotations.
|
|
160
|
+
*
|
|
161
|
+
* @param {Editor} fs - The memfs editor instance.
|
|
162
|
+
* @param {string} basePath - The base path of the project.
|
|
163
|
+
* @param {string} serviceName - Name of The OData service.
|
|
164
|
+
* @param {OdataService} edmxAnnotations - The OData service annotations.
|
|
165
|
+
*/
|
|
166
|
+
function removeRemoteServiceAnnotationXmlFiles(fs, basePath, serviceName, edmxAnnotations) {
|
|
167
|
+
// Write annotation xml if annotations are provided and service type is EDMX
|
|
168
|
+
if (Array.isArray(edmxAnnotations)) {
|
|
169
|
+
for (const annotationName in edmxAnnotations) {
|
|
170
|
+
const annotation = edmxAnnotations[annotationName];
|
|
171
|
+
const pathToAnnotationFile = (0, path_1.join)(basePath, 'webapp', 'localService', serviceName, `${annotation.technicalName}.xml`);
|
|
172
|
+
if (fs.exists(pathToAnnotationFile)) {
|
|
173
|
+
fs.delete(pathToAnnotationFile);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else if (edmxAnnotations?.xml) {
|
|
178
|
+
const pathToAnnotationFile = (0, path_1.join)(basePath, 'webapp', 'localService', serviceName, `${edmxAnnotations.technicalName}.xml`);
|
|
179
|
+
if (fs.exists(pathToAnnotationFile)) {
|
|
180
|
+
fs.delete(pathToAnnotationFile);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Writes annotation XML files for EDMX service annotations.
|
|
186
|
+
*
|
|
187
|
+
* @param {Editor} fs - The memfs editor instance.
|
|
188
|
+
* @param {string} basePath - The base path of the project.
|
|
189
|
+
* @param {string} serviceName - Name of The OData service.
|
|
190
|
+
* @param {OdataService} edmxAnnotations - The OData service annotations.
|
|
191
|
+
*/
|
|
192
|
+
function writeRemoteServiceAnnotationXmlFiles(fs, basePath, serviceName, edmxAnnotations) {
|
|
193
|
+
// Write annotation xml if annotations are provided and service type is EDMX
|
|
194
|
+
if (Array.isArray(edmxAnnotations)) {
|
|
195
|
+
for (const annotationName in edmxAnnotations) {
|
|
196
|
+
const annotation = edmxAnnotations[annotationName];
|
|
197
|
+
if (annotation?.xml) {
|
|
198
|
+
fs.write((0, path_1.join)(basePath, 'webapp', 'localService', serviceName, `${annotation.technicalName}.xml`), (0, prettify_xml_1.default)(annotation.xml, { indent: 4 }));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
else if (edmxAnnotations?.xml) {
|
|
203
|
+
fs.write((0, path_1.join)(basePath, 'webapp', 'localService', serviceName, `${edmxAnnotations.technicalName}.xml`), (0, prettify_xml_1.default)(edmxAnnotations.xml, { indent: 4 }));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
6
206
|
/**
|
|
7
207
|
* Returns the namespaces parsed from the specified metadata and single annotation.
|
|
8
208
|
*
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Editor } from 'mem-fs-editor';
|
|
2
|
+
import type { OdataService } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Internal function that deletes service from the manifest.json based on the given service data.
|
|
5
|
+
*
|
|
6
|
+
* @param basePath - the root path of an existing UI5 application
|
|
7
|
+
* @param service - name of the OData service instance
|
|
8
|
+
* @param fs - the memfs editor instance
|
|
9
|
+
*/
|
|
10
|
+
export declare function deleteServiceFromManifest(basePath: string, service: OdataService, fs: Editor): void;
|
|
11
|
+
/**
|
|
12
|
+
* Updates service data in manifest.json.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} basePath - the root path of an existing UI5 application
|
|
15
|
+
* @param {EdmxOdataService} service - the OData service instance
|
|
16
|
+
* @param {Editor} fs - the memfs editor instance
|
|
17
|
+
* @param {boolean} forceServiceUpdate - if true, checks and updates service annotations
|
|
18
|
+
*/
|
|
19
|
+
export declare function updateManifest(basePath: string, service: OdataService, fs: Editor, forceServiceUpdate?: boolean): Promise<void>;
|
|
20
|
+
//# sourceMappingURL=manifest.d.ts.map
|