@sap-ux/odata-service-inquirer 0.1.1

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.
Files changed (44) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +87 -0
  3. package/dist/error-handler/error-handler.d.ts +176 -0
  4. package/dist/error-handler/error-handler.js +450 -0
  5. package/dist/error-handler/help/help-topics.d.ts +37 -0
  6. package/dist/error-handler/help/help-topics.js +40 -0
  7. package/dist/error-handler/help/images/guidedAnswersIcon_svg_base64.d.ts +2 -0
  8. package/dist/error-handler/help/images/guidedAnswersIcon_svg_base64.js +5 -0
  9. package/dist/error-handler/help/images/index.d.ts +2 -0
  10. package/dist/error-handler/help/images/index.js +18 -0
  11. package/dist/i18n.d.ts +15 -0
  12. package/dist/i18n.js +50 -0
  13. package/dist/index.d.ts +35 -0
  14. package/dist/index.js +73 -0
  15. package/dist/prompts/datasources/cap-project/cap-helpers.d.ts +26 -0
  16. package/dist/prompts/datasources/cap-project/cap-helpers.js +215 -0
  17. package/dist/prompts/datasources/cap-project/questions.d.ts +14 -0
  18. package/dist/prompts/datasources/cap-project/questions.js +172 -0
  19. package/dist/prompts/datasources/cap-project/types.d.ts +27 -0
  20. package/dist/prompts/datasources/cap-project/types.js +12 -0
  21. package/dist/prompts/datasources/cap-project/validators.d.ts +8 -0
  22. package/dist/prompts/datasources/cap-project/validators.js +35 -0
  23. package/dist/prompts/datasources/metadata-file/index.d.ts +10 -0
  24. package/dist/prompts/datasources/metadata-file/index.js +47 -0
  25. package/dist/prompts/datasources/metadata-file/validators.d.ts +13 -0
  26. package/dist/prompts/datasources/metadata-file/validators.js +45 -0
  27. package/dist/prompts/index.d.ts +2 -0
  28. package/dist/prompts/index.js +18 -0
  29. package/dist/prompts/logger-helper.d.ts +20 -0
  30. package/dist/prompts/logger-helper.js +27 -0
  31. package/dist/prompts/prompt-helpers.d.ts +14 -0
  32. package/dist/prompts/prompt-helpers.js +44 -0
  33. package/dist/prompts/prompts.d.ts +9 -0
  34. package/dist/prompts/prompts.js +98 -0
  35. package/dist/prompts/validators.d.ts +13 -0
  36. package/dist/prompts/validators.js +45 -0
  37. package/dist/translations/odata-service-inquirer.i18n.json +88 -0
  38. package/dist/types.d.ts +176 -0
  39. package/dist/types.js +76 -0
  40. package/dist/utils/index.d.ts +26 -0
  41. package/dist/utils/index.js +70 -0
  42. package/dist/utils/prompt-state.d.ts +13 -0
  43. package/dist/utils/prompt-state.js +18 -0
  44. package/package.json +55 -0
@@ -0,0 +1,176 @@
1
+ import type { IValidationLink } from '@sap-devx/yeoman-ui-types';
2
+ import type { YUIQuestion } from '@sap-ux/inquirer-common';
3
+ import type { OdataVersion } from '@sap-ux/odata-service-writer';
4
+ import type { ListChoiceOptions } from 'inquirer';
5
+ /**
6
+ * This file contains types that are exported by the module and are needed for consumers using the APIs `prompt` and `getPrompts`.
7
+ */
8
+ export declare enum DatasourceType {
9
+ sapSystem = "sapSystem",
10
+ businessHub = "businessHub",
11
+ capProject = "capProject",
12
+ odataServiceUrl = "odataServiceUrl",
13
+ none = "none",
14
+ metadataFile = "metadataFile",
15
+ projectSpecificDestination = "projectSpecificDestination"
16
+ }
17
+ /**
18
+ * Answers returned by the OdataServiceInquirer prompt API.
19
+ * These values may be used to write an OData service and may be derived from the user's input rather than direct answers.
20
+ */
21
+ export interface OdataServiceAnswers {
22
+ /**
23
+ * The data source type answer.
24
+ */
25
+ datasourceType: DatasourceType;
26
+ /**
27
+ * The odata service metadata (edmx) document.
28
+ */
29
+ metadata?: string;
30
+ /**
31
+ * The selected CAP service.
32
+ */
33
+ capService?: CapService;
34
+ /**
35
+ * The odata version of the selected service.
36
+ */
37
+ odataVersion?: OdataVersion;
38
+ /**
39
+ * The relative path of the selected service.
40
+ */
41
+ servicePath?: string;
42
+ /**
43
+ * Metadata file path
44
+ */
45
+ metadataFilePath?: string;
46
+ }
47
+ /**
48
+ * Enumeration of prompt names used by OdataServiceInquirerPromptOptions
49
+ */
50
+ export declare enum promptNames {
51
+ /**
52
+ * Data source type
53
+ */
54
+ datasourceType = "datasourceType",
55
+ /**
56
+ * Metadata file path
57
+ */
58
+ metadataFilePath = "metadataFilePath",
59
+ /**
60
+ * Cap project
61
+ */
62
+ capProject = "capProject",
63
+ /**
64
+ * Cap service
65
+ */
66
+ capService = "capService"
67
+ }
68
+ export type CapRuntime = 'Node.js' | 'Java';
69
+ export interface CapService {
70
+ /**
71
+ * The path to the CAP project.
72
+ */
73
+ projectPath: string;
74
+ /**
75
+ * The name of the CAP service as identified by the cds model.
76
+ */
77
+ serviceName: string;
78
+ /**
79
+ * The URL path to the service, as specfied in the manifest.json of generated apps
80
+ * This is also provided as `OdataServicePromptAnswers` property `servicePath`
81
+ */
82
+ urlPath?: string;
83
+ /**
84
+ * The relative path (from the `projectPath`) to the service cds file.
85
+ */
86
+ serviceCdsPath?: string;
87
+ /**
88
+ * The runtime of the CAP service.
89
+ */
90
+ capType?: CapRuntime;
91
+ /**
92
+ * The relative path (from the `projectPath`) to the app folder
93
+ */
94
+ appPath?: string;
95
+ }
96
+ export interface CapServiceChoice extends ListChoiceOptions {
97
+ value: CapService;
98
+ }
99
+ export type CapProjectPromptOptions = {
100
+ /**
101
+ * The search paths for the CAP projects, this is a mandatory option as searching the entire file system is not recommended.
102
+ */
103
+ capSearchPaths: string[];
104
+ /**
105
+ * The default selected CAP project choice, this is used to pre-select a CAP project based on the CAP project path.
106
+ */
107
+ defaultChoice?: string;
108
+ };
109
+ export type CapServicePromptOptions = {
110
+ /**
111
+ * The default selected CAP service choice, this is used to pre-select a CAP service based on the specified CAP service name.
112
+ */
113
+ defaultChoice?: Pick<CapService, 'serviceName' | 'projectPath'>;
114
+ };
115
+ export type DatasourceTypePromptOptions = {
116
+ /**
117
+ * Default datasource type
118
+ */
119
+ default?: DatasourceType;
120
+ /**
121
+ * Include the no datasource option in the datasource type prompt
122
+ */
123
+ includeNone?: boolean;
124
+ /**
125
+ * Include the `projectSpecificDestination` option in the datasource type prompt
126
+ */
127
+ includeProjectSpecificDest?: boolean;
128
+ };
129
+ export type MetadataPromptOptions = {
130
+ /**
131
+ * Used to validate the metadata file contains the required odata version edmx
132
+ */
133
+ requiredOdataVersion?: OdataVersion;
134
+ };
135
+ /**
136
+ * Provide the correct type checking for object value prompt options
137
+ */
138
+ type odataServiceInquirerPromptOptions = Record<promptNames.datasourceType, DatasourceTypePromptOptions> & Record<promptNames.metadataFilePath, MetadataPromptOptions> & Record<promptNames.capProject, CapProjectPromptOptions> & Record<promptNames.capService, CapServicePromptOptions>;
139
+ export type OdataServiceQuestion = YUIQuestion<OdataServiceAnswers>;
140
+ export type OdataServicePromptOptions = Partial<odataServiceInquirerPromptOptions>;
141
+ /**
142
+ * Implementation of IValidationLink interface.
143
+ * Provides a toString() for serialization on CLI since IValidationLink rendering is only supported by YeomanUI.
144
+ */
145
+ export declare class ValidationLink implements IValidationLink {
146
+ message: IValidationLink['message'];
147
+ link: IValidationLink['link'];
148
+ /**
149
+ * Constructor for ValidationLink.
150
+ *
151
+ * @param validationLink The validation link object to be used for serialization
152
+ */
153
+ constructor(validationLink: IValidationLink);
154
+ /**
155
+ * Serialize the validation link object to a string.
156
+ *
157
+ * @returns The validation link object as a string
158
+ */
159
+ toString(): string;
160
+ }
161
+ export declare const hostEnvironment: {
162
+ vscode: {
163
+ name: string;
164
+ technical: string;
165
+ };
166
+ bas: {
167
+ name: string;
168
+ technical: string;
169
+ };
170
+ cli: {
171
+ name: string;
172
+ technical: string;
173
+ };
174
+ };
175
+ export {};
176
+ //# sourceMappingURL=types.d.ts.map
package/dist/types.js ADDED
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hostEnvironment = exports.ValidationLink = exports.promptNames = exports.DatasourceType = void 0;
4
+ /**
5
+ * This file contains types that are exported by the module and are needed for consumers using the APIs `prompt` and `getPrompts`.
6
+ */
7
+ var DatasourceType;
8
+ (function (DatasourceType) {
9
+ DatasourceType["sapSystem"] = "sapSystem";
10
+ DatasourceType["businessHub"] = "businessHub";
11
+ DatasourceType["capProject"] = "capProject";
12
+ DatasourceType["odataServiceUrl"] = "odataServiceUrl";
13
+ DatasourceType["none"] = "none";
14
+ DatasourceType["metadataFile"] = "metadataFile";
15
+ DatasourceType["projectSpecificDestination"] = "projectSpecificDestination";
16
+ })(DatasourceType || (exports.DatasourceType = DatasourceType = {}));
17
+ /**
18
+ * Enumeration of prompt names used by OdataServiceInquirerPromptOptions
19
+ */
20
+ var promptNames;
21
+ (function (promptNames) {
22
+ /**
23
+ * Data source type
24
+ */
25
+ promptNames["datasourceType"] = "datasourceType";
26
+ /**
27
+ * Metadata file path
28
+ */
29
+ promptNames["metadataFilePath"] = "metadataFilePath";
30
+ /**
31
+ * Cap project
32
+ */
33
+ promptNames["capProject"] = "capProject";
34
+ /**
35
+ * Cap service
36
+ */
37
+ promptNames["capService"] = "capService";
38
+ })(promptNames || (exports.promptNames = promptNames = {}));
39
+ /**
40
+ * Implementation of IValidationLink interface.
41
+ * Provides a toString() for serialization on CLI since IValidationLink rendering is only supported by YeomanUI.
42
+ */
43
+ class ValidationLink {
44
+ /**
45
+ * Constructor for ValidationLink.
46
+ *
47
+ * @param validationLink The validation link object to be used for serialization
48
+ */
49
+ constructor(validationLink) {
50
+ Object.assign(this, validationLink);
51
+ }
52
+ /**
53
+ * Serialize the validation link object to a string.
54
+ *
55
+ * @returns The validation link object as a string
56
+ */
57
+ toString() {
58
+ return `${this.message} ${this.link.text}${this.link.url ? ' : ' + this.link.url : ''}`;
59
+ }
60
+ }
61
+ exports.ValidationLink = ValidationLink;
62
+ exports.hostEnvironment = {
63
+ vscode: {
64
+ name: 'Visual Studio Code',
65
+ technical: 'VSCode'
66
+ },
67
+ bas: {
68
+ name: 'SAP Business Application Studio',
69
+ technical: 'SBAS'
70
+ },
71
+ cli: {
72
+ name: 'CLI',
73
+ technical: 'CLI'
74
+ }
75
+ };
76
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,26 @@
1
+ import type { TelemetryProperties, ToolsSuiteTelemetryClient } from '@sap-ux/telemetry';
2
+ import { PromptState } from './prompt-state';
3
+ /**
4
+ * Determine if the current prompting environment is cli or a hosted extension (app studio or vscode).
5
+ *
6
+ * @returns the platform name and technical name
7
+ */
8
+ export declare function getPlatform(): {
9
+ name: string;
10
+ technical: string;
11
+ };
12
+ /**
13
+ * Set the telemetry client.
14
+ *
15
+ * @param toolsSuiteTelemetryClient the telemetry client instance to use when sending telemetry events
16
+ */
17
+ export declare function setTelemetryClient(toolsSuiteTelemetryClient: ToolsSuiteTelemetryClient | undefined): void;
18
+ /**
19
+ * Send telemetry event.
20
+ *
21
+ * @param eventName the name of the telemetry event
22
+ * @param telemetryData the telemetry values to report
23
+ */
24
+ export declare function sendTelemetryEvent(eventName: string, telemetryData: TelemetryProperties): void;
25
+ export { PromptState };
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,70 @@
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.PromptState = exports.sendTelemetryEvent = exports.setTelemetryClient = exports.getPlatform = void 0;
7
+ const btp_utils_1 = require("@sap-ux/btp-utils");
8
+ const telemetry_1 = require("@sap-ux/telemetry");
9
+ const os_name_1 = __importDefault(require("os-name"));
10
+ const types_1 = require("../types");
11
+ const prompt_state_1 = require("./prompt-state");
12
+ Object.defineProperty(exports, "PromptState", { enumerable: true, get: function () { return prompt_state_1.PromptState; } });
13
+ const osVersionName = (0, os_name_1.default)();
14
+ /**
15
+ * Determine if the current prompting environment is cli or a hosted extension (app studio or vscode).
16
+ *
17
+ * @returns the platform name and technical name
18
+ */
19
+ function getPlatform() {
20
+ if (!prompt_state_1.PromptState.isYUI) {
21
+ return types_1.hostEnvironment.cli;
22
+ }
23
+ else {
24
+ return (0, btp_utils_1.isAppStudio)() ? types_1.hostEnvironment.bas : types_1.hostEnvironment.vscode;
25
+ }
26
+ }
27
+ exports.getPlatform = getPlatform;
28
+ let telemetryClient;
29
+ /**
30
+ * Set the telemetry client.
31
+ *
32
+ * @param toolsSuiteTelemetryClient the telemetry client instance to use when sending telemetry events
33
+ */
34
+ function setTelemetryClient(toolsSuiteTelemetryClient) {
35
+ telemetryClient = toolsSuiteTelemetryClient;
36
+ }
37
+ exports.setTelemetryClient = setTelemetryClient;
38
+ /**
39
+ * Send telemetry event.
40
+ *
41
+ * @param eventName the name of the telemetry event
42
+ * @param telemetryData the telemetry values to report
43
+ */
44
+ function sendTelemetryEvent(eventName, telemetryData) {
45
+ const telemetryEvent = createTelemetryEvent(eventName, telemetryData);
46
+ if (telemetryClient) {
47
+ /* eslint-disable @typescript-eslint/no-floating-promises */
48
+ telemetryClient.reportEvent(telemetryEvent, telemetry_1.SampleRate.NoSampling);
49
+ }
50
+ }
51
+ exports.sendTelemetryEvent = sendTelemetryEvent;
52
+ /**
53
+ * Create telemetry event.
54
+ *
55
+ * @param eventName the name of the telemetry event
56
+ * @param telemetryData the telemetry values to add to he returned telemetry event
57
+ * @returns the telemetry event
58
+ */
59
+ function createTelemetryEvent(eventName, telemetryData) {
60
+ const telemProps = Object.assign(telemetryData, {
61
+ Platform: getPlatform().technical,
62
+ OperatingSystem: osVersionName
63
+ });
64
+ return {
65
+ eventName,
66
+ properties: telemProps,
67
+ measurements: {}
68
+ };
69
+ }
70
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,13 @@
1
+ import type { OdataServiceAnswers } from '../types';
2
+ /**
3
+ * Much of the values returned by the service inquirer prompting are derived from prompt answers and are not direct answer values.
4
+ * Since inquirer does not provide a way to return values that are not direct answers from prompts, this class will maintain the derived values
5
+ * across prompts statically for the lifespan of the prompting session.
6
+ *
7
+ */
8
+ export declare class PromptState {
9
+ static odataService: Partial<OdataServiceAnswers>;
10
+ static isYUI: boolean;
11
+ static reset(): void;
12
+ }
13
+ //# sourceMappingURL=prompt-state.d.ts.map
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PromptState = void 0;
4
+ /**
5
+ * Much of the values returned by the service inquirer prompting are derived from prompt answers and are not direct answer values.
6
+ * Since inquirer does not provide a way to return values that are not direct answers from prompts, this class will maintain the derived values
7
+ * across prompts statically for the lifespan of the prompting session.
8
+ *
9
+ */
10
+ class PromptState {
11
+ static reset() {
12
+ PromptState.odataService = {};
13
+ }
14
+ }
15
+ exports.PromptState = PromptState;
16
+ PromptState.odataService = {};
17
+ PromptState.isYUI = false;
18
+ //# sourceMappingURL=prompt-state.js.map
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@sap-ux/odata-service-inquirer",
3
+ "description": "Prompts module that can prompt users for inputs required for odata service writing",
4
+ "version": "0.1.1",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/SAP/open-ux-tools.git",
8
+ "directory": "packages/odata-sevice-inquirer"
9
+ },
10
+ "bugs": {
11
+ "url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Aodata-service-inquirer"
12
+ },
13
+ "license": "Apache-2.0",
14
+ "main": "dist/index.js",
15
+ "files": [
16
+ "LICENSE",
17
+ "dist",
18
+ "!dist/*.map",
19
+ "!dist/**/*.map"
20
+ ],
21
+ "dependencies": {
22
+ "@sap/wing-service-explorer": "1.8.0",
23
+ "i18next": "23.5.1",
24
+ "os-name": "4.0.1",
25
+ "@sap-ux/btp-utils": "0.14.3",
26
+ "@sap-ux/telemetry": "0.4.21",
27
+ "@sap-ux/inquirer-common": "0.2.7",
28
+ "@sap-ux/logger": "0.5.1",
29
+ "@sap-ux/project-access": "1.19.14"
30
+ },
31
+ "devDependencies": {
32
+ "@sap-devx/yeoman-ui-types": "1.14.4",
33
+ "@types/inquirer-autocomplete-prompt": "2.0.1",
34
+ "@types/inquirer": "8.2.6",
35
+ "@types/lodash": "4.14.202",
36
+ "jest-extended": "3.2.4",
37
+ "lodash": "4.17.21",
38
+ "@sap-ux/odata-service-writer": "0.17.1",
39
+ "@sap-ux/feature-toggle": "0.1.1"
40
+ },
41
+ "engines": {
42
+ "node": ">=18.x"
43
+ },
44
+ "scripts": {
45
+ "build": "tsc --build",
46
+ "clean": "rimraf --glob dist test/test-output coverage *.tsbuildinfo",
47
+ "watch": "tsc --watch",
48
+ "lint": "eslint . --ext .ts",
49
+ "lint:fix": "eslint . --ext .ts --fix",
50
+ "test": "jest --ci --forceExit --detectOpenHandles --colors --passWithNoTests",
51
+ "test-u": "jest --ci --forceExit --detectOpenHandles --colors -u",
52
+ "link": "pnpm link --global",
53
+ "unlink": "pnpm unlink --global"
54
+ }
55
+ }