@sap-ux/adp-tooling 0.8.11 → 0.9.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.
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.AnnotationsWriter = void 0;
16
+ const path_1 = __importDefault(require("path"));
17
+ const change_utils_1 = require("../../../base/change-utils");
18
+ /**
19
+ * Handles the creation and writing of annotations data changes for a project.
20
+ */
21
+ class AnnotationsWriter {
22
+ /**
23
+ * @param {Editor} fs - The filesystem editor instance.
24
+ * @param {string} projectPath - The root path of the project.
25
+ */
26
+ constructor(fs, projectPath) {
27
+ this.fs = fs;
28
+ this.projectPath = projectPath;
29
+ }
30
+ /**
31
+ * Constructs the content for an annotation change based on provided data.
32
+ *
33
+ * @param {AnnotationsData} data - The data object containing information needed to construct the content property.
34
+ * @returns {object} The constructed content object for the annotation change.
35
+ */
36
+ constructContent(data) {
37
+ const { isInternalUsage, annotation: { dataSource, fileName } } = data;
38
+ const annotationFileNameWithoutExtension = fileName === null || fileName === void 0 ? void 0 : fileName.toLocaleLowerCase().replace('.xml', '');
39
+ const annotationNameSpace = isInternalUsage
40
+ ? `annotation.${annotationFileNameWithoutExtension}`
41
+ : `customer.annotation.${annotationFileNameWithoutExtension}`;
42
+ return {
43
+ dataSourceId: `${dataSource}`,
44
+ annotations: [annotationNameSpace],
45
+ annotationsInsertPosition: 'END',
46
+ dataSource: {
47
+ [annotationNameSpace]: {
48
+ uri: `../annotations/${fileName}`,
49
+ type: 'ODataAnnotation'
50
+ }
51
+ }
52
+ };
53
+ }
54
+ /**
55
+ * Determines the appropriate filename for the annotation file based on user answers.
56
+ *
57
+ * @param {AnnotationsData} data - The answers object containing user choices.
58
+ * @returns {string | undefined} The determined filename for the annotation file.
59
+ */
60
+ getAnnotationFileName({ annotation }) {
61
+ return annotation.filePath ? path_1.default.basename(annotation.filePath) : `annotation_${Date.now()}.xml`;
62
+ }
63
+ /**
64
+ * Writes the annotation change to the project based on the provided data.
65
+ *
66
+ * @param {AnnotationsData} data - The annotations data containing all the necessary information to construct and write the change.
67
+ * @returns {Promise<void>} A promise that resolves when the change writing process is completed.
68
+ */
69
+ write(data) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ data.annotation.fileName = this.getAnnotationFileName(data);
72
+ const content = this.constructContent(data);
73
+ const change = (0, change_utils_1.getGenericChange)(data, content, "appdescr_app_addAnnotationsToOData" /* ChangeType.ADD_ANNOTATIONS_TO_ODATA */);
74
+ (0, change_utils_1.writeAnnotationChange)(this.projectPath, data, change, this.fs);
75
+ });
76
+ }
77
+ }
78
+ exports.AnnotationsWriter = AnnotationsWriter;
79
+ //# sourceMappingURL=annotations-writer.js.map
@@ -0,0 +1,36 @@
1
+ import type { Editor } from 'mem-fs-editor';
2
+ import type { IWriter, ComponentUsagesData } from '../../../types';
3
+ /**
4
+ * Handles the creation and writing of component usages data changes for a project.
5
+ */
6
+ export declare class ComponentUsagesWriter implements IWriter<ComponentUsagesData> {
7
+ private fs;
8
+ private projectPath;
9
+ /**
10
+ * @param {Editor} fs - The filesystem editor instance.
11
+ * @param {string} projectPath - The root path of the project.
12
+ */
13
+ constructor(fs: Editor, projectPath: string);
14
+ /**
15
+ * Constructs the content for an component usages change based on provided data.
16
+ *
17
+ * @param {ComponentUsagesData} data - The answers object containing information needed to construct the content property.
18
+ * @returns {object} The constructed content object for the component usages change.
19
+ */
20
+ private constructContent;
21
+ /**
22
+ * Constructs the content for an library reference change based on provided data.
23
+ *
24
+ * @param {ComponentUsagesData} data - The answers object containing information needed to construct the content property.
25
+ * @returns {object | undefined} The constructed content object for the library reference change.
26
+ */
27
+ private constructLibContent;
28
+ /**
29
+ * Writes the component usages change to the project based on the provided data.
30
+ *
31
+ * @param {ComponentUsagesData} data - The component usages data containing all the necessary information to construct and write the change.
32
+ * @returns {Promise<void>} A promise that resolves when the change writing process is completed.
33
+ */
34
+ write(data: ComponentUsagesData): Promise<void>;
35
+ }
36
+ //# sourceMappingURL=component-usages-writer.d.ts.map
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ComponentUsagesWriter = void 0;
13
+ const change_utils_1 = require("../../../base/change-utils");
14
+ /**
15
+ * Handles the creation and writing of component usages data changes for a project.
16
+ */
17
+ class ComponentUsagesWriter {
18
+ /**
19
+ * @param {Editor} fs - The filesystem editor instance.
20
+ * @param {string} projectPath - The root path of the project.
21
+ */
22
+ constructor(fs, projectPath) {
23
+ this.fs = fs;
24
+ this.projectPath = projectPath;
25
+ }
26
+ /**
27
+ * Constructs the content for an component usages change based on provided data.
28
+ *
29
+ * @param {ComponentUsagesData} data - The answers object containing information needed to construct the content property.
30
+ * @returns {object} The constructed content object for the component usages change.
31
+ */
32
+ constructContent({ component }) {
33
+ const { data, usageId, settings, isLazy } = component;
34
+ const componentUsages = {
35
+ [usageId]: {
36
+ name: usageId,
37
+ lazy: isLazy === 'true',
38
+ settings: (0, change_utils_1.parseStringToObject)(settings),
39
+ data: (0, change_utils_1.parseStringToObject)(data)
40
+ }
41
+ };
42
+ return {
43
+ componentUsages
44
+ };
45
+ }
46
+ /**
47
+ * Constructs the content for an library reference change based on provided data.
48
+ *
49
+ * @param {ComponentUsagesData} data - The answers object containing information needed to construct the content property.
50
+ * @returns {object | undefined} The constructed content object for the library reference change.
51
+ */
52
+ constructLibContent(data) {
53
+ const library = data.library;
54
+ if (!library.reference) {
55
+ return undefined;
56
+ }
57
+ return {
58
+ libraries: {
59
+ [library.reference]: {
60
+ lazy: library.referenceIsLazy === 'true'
61
+ }
62
+ }
63
+ };
64
+ }
65
+ /**
66
+ * Writes the component usages change to the project based on the provided data.
67
+ *
68
+ * @param {ComponentUsagesData} data - The component usages data containing all the necessary information to construct and write the change.
69
+ * @returns {Promise<void>} A promise that resolves when the change writing process is completed.
70
+ */
71
+ write(data) {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ const componentUsagesContent = this.constructContent(data);
74
+ const libRefContent = this.constructLibContent(data);
75
+ const shouldAddLibRef = libRefContent !== undefined;
76
+ const compUsagesChange = (0, change_utils_1.getGenericChange)(data, componentUsagesContent, "appdescr_ui5_addComponentUsages" /* ChangeType.ADD_COMPONENT_USAGES */);
77
+ (0, change_utils_1.writeChangeToFolder)(this.projectPath, compUsagesChange, `id_${data.timestamp}_addComponentUsages.change`, this.fs, "manifest" /* FolderTypes.MANIFEST */);
78
+ if (shouldAddLibRef) {
79
+ data.timestamp += 1;
80
+ const refLibChange = (0, change_utils_1.getGenericChange)(data, libRefContent, "appdescr_ui5_addLibraries" /* ChangeType.ADD_LIBRARY_REFERENCE */);
81
+ (0, change_utils_1.writeChangeToFolder)(this.projectPath, refLibChange, `id_${data.timestamp}_addLibraries.change`, this.fs, "manifest" /* FolderTypes.MANIFEST */);
82
+ }
83
+ });
84
+ }
85
+ }
86
+ exports.ComponentUsagesWriter = ComponentUsagesWriter;
87
+ //# sourceMappingURL=component-usages-writer.js.map
@@ -0,0 +1,31 @@
1
+ import type { Editor } from 'mem-fs-editor';
2
+ import type { IWriter, DataSourceData } from '../../../types';
3
+ /**
4
+ * Handles the creation and writing of data source data changes for a project.
5
+ */
6
+ export declare class DataSourceWriter implements IWriter<DataSourceData> {
7
+ private fs;
8
+ private projectPath;
9
+ /**
10
+ * @param {Editor} fs - The filesystem editor instance.
11
+ * @param {string} projectPath - The root path of the project.
12
+ */
13
+ constructor(fs: Editor, projectPath: string);
14
+ /**
15
+ * Constructs content for a data source change.
16
+ *
17
+ * @param {string} dataSourceId - The ID of the data source being modified.
18
+ * @param {string} dataSourceUri - The new URI to update the data source with.
19
+ * @param {number} [maxAge] - Optional maximum age.
20
+ * @returns {object} The constructed content object for the change data source change.
21
+ */
22
+ private constructContent;
23
+ /**
24
+ * Writes the change data source change to the project based on the provided data.
25
+ *
26
+ * @param {DataSourceData} data - The change data source data containing all the necessary information to construct and write the change.
27
+ * @returns {Promise<void>} A promise that resolves when the change writing process is completed.
28
+ */
29
+ write(data: DataSourceData): Promise<void>;
30
+ }
31
+ //# sourceMappingURL=data-source-writer.d.ts.map
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DataSourceWriter = void 0;
13
+ const change_utils_1 = require("../../../base/change-utils");
14
+ /**
15
+ * Handles the creation and writing of data source data changes for a project.
16
+ */
17
+ class DataSourceWriter {
18
+ /**
19
+ * @param {Editor} fs - The filesystem editor instance.
20
+ * @param {string} projectPath - The root path of the project.
21
+ */
22
+ constructor(fs, projectPath) {
23
+ this.fs = fs;
24
+ this.projectPath = projectPath;
25
+ }
26
+ /**
27
+ * Constructs content for a data source change.
28
+ *
29
+ * @param {string} dataSourceId - The ID of the data source being modified.
30
+ * @param {string} dataSourceUri - The new URI to update the data source with.
31
+ * @param {number} [maxAge] - Optional maximum age.
32
+ * @returns {object} The constructed content object for the change data source change.
33
+ */
34
+ constructContent(dataSourceId, dataSourceUri, maxAge) {
35
+ const content = {
36
+ dataSourceId: dataSourceId,
37
+ entityPropertyChange: [
38
+ {
39
+ propertyPath: 'uri',
40
+ operation: 'UPDATE',
41
+ propertyValue: dataSourceUri
42
+ }
43
+ ]
44
+ };
45
+ if (maxAge) {
46
+ content.entityPropertyChange.push({
47
+ propertyPath: 'settings/maxAge',
48
+ operation: 'UPSERT',
49
+ propertyValue: Number(maxAge)
50
+ });
51
+ }
52
+ return content;
53
+ }
54
+ /**
55
+ * Writes the change data source change to the project based on the provided data.
56
+ *
57
+ * @param {DataSourceData} data - The change data source data containing all the necessary information to construct and write the change.
58
+ * @returns {Promise<void>} A promise that resolves when the change writing process is completed.
59
+ */
60
+ write(data) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ const { dataSourcesDictionary, service } = data;
63
+ const content = this.constructContent(service.name, service.uri, service.maxAge);
64
+ const change = (0, change_utils_1.getGenericChange)(data, content, "appdescr_app_changeDataSource" /* ChangeType.CHANGE_DATA_SOURCE */);
65
+ (0, change_utils_1.writeChangeToFolder)(this.projectPath, change, `id_${data.timestamp}_changeDataSource.change`, this.fs, "manifest" /* FolderTypes.MANIFEST */);
66
+ const shouldAddAnnotation = service.annotationUri && service.annotationUri.length > 0;
67
+ if (shouldAddAnnotation) {
68
+ data.timestamp += 1;
69
+ const annotationContent = this.constructContent(dataSourcesDictionary[service.name], service.annotationUri);
70
+ const annotationChange = (0, change_utils_1.getGenericChange)(data, annotationContent, "appdescr_app_changeDataSource" /* ChangeType.CHANGE_DATA_SOURCE */);
71
+ (0, change_utils_1.writeChangeToFolder)(this.projectPath, annotationChange, `id_${data.timestamp}_changeDataSource.change`, this.fs, "manifest" /* FolderTypes.MANIFEST */);
72
+ }
73
+ });
74
+ }
75
+ }
76
+ exports.DataSourceWriter = DataSourceWriter;
77
+ //# sourceMappingURL=data-source-writer.js.map
@@ -0,0 +1,45 @@
1
+ import type { Editor } from 'mem-fs-editor';
2
+ import type { IWriter, InboundData } from '../../../types';
3
+ /**
4
+ * Handles the creation and writing of inbound data changes for a project.
5
+ */
6
+ export declare class InboundWriter implements IWriter<InboundData> {
7
+ private fs;
8
+ private projectPath;
9
+ /**
10
+ * @param {Editor} fs - The filesystem editor instance.
11
+ * @param {string} projectPath - The root path of the project.
12
+ */
13
+ constructor(fs: Editor, projectPath: string);
14
+ /**
15
+ * Constructs the content for an inbound data change based on provided data.
16
+ *
17
+ * @param {InboundData} data - The answers object containing information needed to construct the content property.
18
+ * @returns {object} The constructed content object for the inbound data change.
19
+ */
20
+ private constructContent;
21
+ /**
22
+ * Enhances the provided content object based on the values provided in answers.
23
+ *
24
+ * @param {InboundData} data - An object containing potential values for title, subTitle, and icon.
25
+ * @param {InboundContent} content - The initial content object to be enhanced.
26
+ * @returns {void}
27
+ */
28
+ private getEnhancedContent;
29
+ /**
30
+ * Processes the provided answers object to parse its properties into the correct format.
31
+ *
32
+ * @param {InboundData} data - An object containing raw answers for inboundId, title, subTitle, and icon.
33
+ * @returns {InboundData} A new answers object with properties modified
34
+ * to ensure they are in the correct format for use in content construction.
35
+ */
36
+ private getModifiedData;
37
+ /**
38
+ * Writes the inbound data change to the project based on the provided data.
39
+ *
40
+ * @param {InboundData} data - The inbound data containing all the necessary information to construct and write the change.
41
+ * @returns {Promise<void>} A promise that resolves when the change writing process is completed.
42
+ */
43
+ write(data: InboundData): Promise<void>;
44
+ }
45
+ //# sourceMappingURL=inbound-writer.d.ts.map
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.InboundWriter = void 0;
13
+ const change_utils_1 = require("../../../base/change-utils");
14
+ /**
15
+ * Handles the creation and writing of inbound data changes for a project.
16
+ */
17
+ class InboundWriter {
18
+ /**
19
+ * @param {Editor} fs - The filesystem editor instance.
20
+ * @param {string} projectPath - The root path of the project.
21
+ */
22
+ constructor(fs, projectPath) {
23
+ this.fs = fs;
24
+ this.projectPath = projectPath;
25
+ }
26
+ /**
27
+ * Constructs the content for an inbound data change based on provided data.
28
+ *
29
+ * @param {InboundData} data - The answers object containing information needed to construct the content property.
30
+ * @returns {object} The constructed content object for the inbound data change.
31
+ */
32
+ constructContent(data) {
33
+ const content = {
34
+ inboundId: data.inboundId,
35
+ entityPropertyChange: []
36
+ };
37
+ this.getEnhancedContent(data, content);
38
+ return content;
39
+ }
40
+ /**
41
+ * Enhances the provided content object based on the values provided in answers.
42
+ *
43
+ * @param {InboundData} data - An object containing potential values for title, subTitle, and icon.
44
+ * @param {InboundContent} content - The initial content object to be enhanced.
45
+ * @returns {void}
46
+ */
47
+ getEnhancedContent(data, content) {
48
+ const { icon, title, subTitle } = data.flp;
49
+ if (title) {
50
+ content.entityPropertyChange.push({
51
+ propertyPath: 'title',
52
+ operation: 'UPSERT',
53
+ propertyValue: title
54
+ });
55
+ }
56
+ if (subTitle) {
57
+ content.entityPropertyChange.push({
58
+ propertyPath: 'subTitle',
59
+ operation: 'UPSERT',
60
+ propertyValue: subTitle
61
+ });
62
+ }
63
+ if (icon) {
64
+ content.entityPropertyChange.push({
65
+ propertyPath: 'icon',
66
+ operation: 'UPSERT',
67
+ propertyValue: icon
68
+ });
69
+ }
70
+ }
71
+ /**
72
+ * Processes the provided answers object to parse its properties into the correct format.
73
+ *
74
+ * @param {InboundData} data - An object containing raw answers for inboundId, title, subTitle, and icon.
75
+ * @returns {InboundData} A new answers object with properties modified
76
+ * to ensure they are in the correct format for use in content construction.
77
+ */
78
+ getModifiedData(data) {
79
+ const { title, subTitle, icon } = data.flp;
80
+ return Object.assign(Object.assign({}, data), { flp: {
81
+ title: (0, change_utils_1.getParsedPropertyValue)(title),
82
+ subTitle: (0, change_utils_1.getParsedPropertyValue)(subTitle),
83
+ icon: (0, change_utils_1.getParsedPropertyValue)(icon)
84
+ } });
85
+ }
86
+ /**
87
+ * Writes the inbound data change to the project based on the provided data.
88
+ *
89
+ * @param {InboundData} data - The inbound data containing all the necessary information to construct and write the change.
90
+ * @returns {Promise<void>} A promise that resolves when the change writing process is completed.
91
+ */
92
+ write(data) {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ const answers = this.getModifiedData(data);
95
+ const { changeWithInboundId, filePath } = (0, change_utils_1.findChangeWithInboundId)(this.projectPath, answers.inboundId);
96
+ if (!changeWithInboundId) {
97
+ const content = this.constructContent(answers);
98
+ const change = (0, change_utils_1.getGenericChange)(data, content, "appdescr_app_changeInbound" /* ChangeType.CHANGE_INBOUND */);
99
+ (0, change_utils_1.writeChangeToFolder)(this.projectPath, change, `id_${data.timestamp}_changeInbound.change`, this.fs, "manifest" /* FolderTypes.MANIFEST */);
100
+ }
101
+ else {
102
+ if (changeWithInboundId.content) {
103
+ this.getEnhancedContent(answers, changeWithInboundId.content);
104
+ }
105
+ (0, change_utils_1.writeChangeToFile)(filePath, changeWithInboundId, this.fs);
106
+ }
107
+ });
108
+ }
109
+ }
110
+ exports.InboundWriter = InboundWriter;
111
+ //# sourceMappingURL=inbound-writer.js.map
@@ -0,0 +1,6 @@
1
+ export * from './annotations-writer';
2
+ export * from './component-usages-writer';
3
+ export * from './data-source-writer';
4
+ export * from './inbound-writer';
5
+ export * from './new-model-writer';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./annotations-writer"), exports);
18
+ __exportStar(require("./component-usages-writer"), exports);
19
+ __exportStar(require("./data-source-writer"), exports);
20
+ __exportStar(require("./inbound-writer"), exports);
21
+ __exportStar(require("./new-model-writer"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,29 @@
1
+ import type { Editor } from 'mem-fs-editor';
2
+ import type { IWriter, NewModelData } from '../../../types';
3
+ /**
4
+ * Handles the creation and writing of new sapui5 model data changes for a project.
5
+ */
6
+ export declare class NewModelWriter implements IWriter<NewModelData> {
7
+ private fs;
8
+ private projectPath;
9
+ /**
10
+ * @param {Editor} fs - The filesystem editor instance.
11
+ * @param {string} projectPath - The root path of the project.
12
+ */
13
+ constructor(fs: Editor, projectPath: string);
14
+ /**
15
+ * Constructs the content for an new model change based on provided data.
16
+ *
17
+ * @param {NewModelData} data - The answers object containing information needed to construct the content property.
18
+ * @returns {object} The constructed content object for the new model change.
19
+ */
20
+ private constructContent;
21
+ /**
22
+ * Writes the new model change to the project based on the provided data.
23
+ *
24
+ * @param {NewModelData} data - The new model data containing all the necessary information to construct and write the change.
25
+ * @returns {Promise<void>} A promise that resolves when the change writing process is completed.
26
+ */
27
+ write(data: NewModelData): Promise<void>;
28
+ }
29
+ //# sourceMappingURL=new-model-writer.d.ts.map
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.NewModelWriter = void 0;
13
+ const change_utils_1 = require("../../../base/change-utils");
14
+ /**
15
+ * Handles the creation and writing of new sapui5 model data changes for a project.
16
+ */
17
+ class NewModelWriter {
18
+ /**
19
+ * @param {Editor} fs - The filesystem editor instance.
20
+ * @param {string} projectPath - The root path of the project.
21
+ */
22
+ constructor(fs, projectPath) {
23
+ this.fs = fs;
24
+ this.projectPath = projectPath;
25
+ }
26
+ /**
27
+ * Constructs the content for an new model change based on provided data.
28
+ *
29
+ * @param {NewModelData} data - The answers object containing information needed to construct the content property.
30
+ * @returns {object} The constructed content object for the new model change.
31
+ */
32
+ constructContent({ service, annotation, addAnnotationMode }) {
33
+ const content = {
34
+ dataSource: {
35
+ [service.name]: {
36
+ uri: service.uri,
37
+ type: 'OData',
38
+ settings: {
39
+ version: service.version
40
+ }
41
+ }
42
+ },
43
+ model: {
44
+ [service.modelName]: {
45
+ dataSource: service.name
46
+ }
47
+ }
48
+ };
49
+ if (service.modelSettings && service.modelSettings.length !== 0) {
50
+ content.model[service.modelName].settings = (0, change_utils_1.parseStringToObject)(service.modelSettings);
51
+ }
52
+ if (addAnnotationMode) {
53
+ content.dataSource[service.name].settings.annotations = [`${annotation.dataSourceName}`];
54
+ content.dataSource[annotation.dataSourceName] = {
55
+ uri: annotation.dataSourceURI,
56
+ type: 'ODataAnnotation'
57
+ };
58
+ if (annotation.settings && annotation.settings.length !== 0) {
59
+ content.dataSource[annotation.dataSourceName].settings = (0, change_utils_1.parseStringToObject)(annotation.settings);
60
+ }
61
+ }
62
+ return content;
63
+ }
64
+ /**
65
+ * Writes the new model change to the project based on the provided data.
66
+ *
67
+ * @param {NewModelData} data - The new model data containing all the necessary information to construct and write the change.
68
+ * @returns {Promise<void>} A promise that resolves when the change writing process is completed.
69
+ */
70
+ write(data) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ const content = this.constructContent(data);
73
+ const change = (0, change_utils_1.getGenericChange)(data, content, "appdescr_ui5_addNewModel" /* ChangeType.ADD_NEW_MODEL */);
74
+ (0, change_utils_1.writeChangeToFolder)(this.projectPath, change, `id_${data.timestamp}_addNewModel.change`, this.fs, "manifest" /* FolderTypes.MANIFEST */);
75
+ });
76
+ }
77
+ }
78
+ exports.NewModelWriter = NewModelWriter;
79
+ //# sourceMappingURL=new-model-writer.js.map
@@ -0,0 +1,18 @@
1
+ import { type Editor } from 'mem-fs-editor';
2
+ import type { GeneratorData, ChangeType } from '../types';
3
+ /**
4
+ * Generates and applies changes to a project based on a specified generator type.
5
+ *
6
+ * This function initializes the file system editor if not provided, selects the appropriate writer based on the generator type,
7
+ * and then invokes the writer's write method to apply changes. The changes are made in-memory and need to be committed
8
+ * to be reflected on the disk.
9
+ *
10
+ * @param {string} projectPath - The root path of the project.
11
+ * @param {T} type - The type of generator.
12
+ * @param {GeneratorData<T>} data - The data specific to the type of generator, containing information necessary for making changes.
13
+ * @param {Editor | null} [fs] - The `mem-fs-editor` instance used for file operations.
14
+ * @returns {Promise<Editor>} A promise that resolves to the mem-fs editor instance used for making changes, allowing for further operations or committing changes to disk.
15
+ * @template T - A type parameter extending `ChangeType`, ensuring the function handles a defined set of generator types.
16
+ */
17
+ export declare function generateChange<T extends ChangeType>(projectPath: string, type: T, data: GeneratorData<T>, fs?: Editor | null): Promise<Editor>;
18
+ //# sourceMappingURL=editors.d.ts.map