@sap-ux/project-access
Version:
Library to access SAP Fiori tools projects
227 lines • 11.1 kB
TypeScript
import type { Logger } from '@sap-ux/logger';
import type { Editor } from 'mem-fs-editor';
import type { CapCustomPaths, CapProjectType, CdsEnvironment, csn, Package, ServiceDefinitions, ServiceInfo, CdsVersionInfo, CdsUi5PluginInfo } from '../types/index.js';
/**
* Returns true if the project is a CAP Node.js project.
*
* @param packageJson - the parsed package.json object
* @returns - true if the project is a CAP Node.js project
*/
export declare function isCapNodeJsProject(packageJson: Package): boolean;
/**
* Returns true if the project is a CAP Java project.
*
* @param projectRoot - the root path of the project
* @param [capCustomPaths] - optional, relative CAP paths like app, db, srv
* @param memFs - optional mem-fs-editor instance
* @returns - true if the project is a CAP project
*/
export declare function isCapJavaProject(projectRoot: string, capCustomPaths?: CapCustomPaths, memFs?: Editor): Promise<boolean>;
/**
* Returns the CAP project type, undefined if it is not a CAP project.
*
* @param projectRoot - root of the project, where the package.json resides.
* @param memFs - optional mem-fs-editor instance
* @returns - CAPJava for Java based CAP projects; CAPNodejs for node.js based CAP projects; undefined if it is no CAP project
*/
export declare function getCapProjectType(projectRoot: string, memFs?: Editor): Promise<CapProjectType | undefined>;
/**
* Returns true if the project is either a CAP Node.js or a CAP Java project.
*
* @param projectRoot - the root path of the project
* @returns - true if the project is a CAP project
*/
export declare function isCapProject(projectRoot: string): Promise<boolean>;
/**
* Get CAP CDS project custom paths for project root.
*
* @param capProjectPath - project root of cap project
* @returns - paths to app, db, and srv for CAP project
*/
export declare function getCapCustomPaths(capProjectPath: string): Promise<CapCustomPaths>;
/**
* Return the CAP model and all services. The cds.root will be set to the provided project root path.
*
* @param projectRoot - CAP project root where package.json resides or object specifying project root and optional logger to log additional info
* @returns {Promise<{ model: csn; services: ServiceInfo[]; cdsVersionInfo: CdsVersionInfo }>} - CAP Model and Services
*/
export declare function getCapModelAndServices(projectRoot: string | {
projectRoot: string;
logger?: Logger;
pathSelection?: Set<'app' | 'srv' | 'db'>;
}): Promise<{
model: csn;
services: ServiceInfo[];
cdsVersionInfo: CdsVersionInfo;
}>;
/**
* Filter and normalize service definitions from CAP project.
*
* @param services - list of services from cds.compile.to['serviceinfo'](model)
* @returns list of normalized service info
*/
export declare function processServices(services: ServiceInfo[] | object | undefined): ServiceInfo[];
/**
* Returns a list of cds file paths (layers). By default return list of all, but you can also restrict it to one envRoot.
*
* @param projectRoot - root of the project, where the package.json is
* @param [ignoreErrors] - optionally, default is false; if set to true the thrown error will be checked for CDS file paths in model and returned
* @param [envRoot] - optionally, the root folder or CDS file to get the layer files
* @returns - array of strings containing cds file paths
*/
export declare function getCdsFiles(projectRoot: string, ignoreErrors?: boolean, envRoot?: string | string[]): Promise<string[]>;
/**
* Returns a list of filepaths to CDS files in root folders. Same what is done if you execute cds.resolve('*') on command line in a project.
*
* @param projectRoot - root of the project, where the package.json is
* @param [clearCache] - optionally, clear the cache, default false
* @returns - array of root paths
*/
export declare function getCdsRoots(projectRoot: string, clearCache?: boolean): Promise<string[]>;
/**
* Return a list of services in a CAP project.
*
* @param projectRoot - root of the CAP project, where the package.json is
* @param ignoreErrors - in case loading the cds model throws an error, try to use the model from the exception object
* @returns - array of service definitions
*/
export declare function getCdsServices(projectRoot: string, ignoreErrors?: boolean): Promise<ServiceDefinitions[]>;
/**
* Return the EDMX string of a CAP service.
*
* @param root - CAP project root where package.json resides
* @param uri - service path, e.g 'incident/'
* @param version - optional OData version v2 or v4
* @returns - string containing the edmx
*/
export declare function readCapServiceMetadataEdmx(root: string, uri: string, version?: 'v2' | 'v4'): Promise<string>;
/**
* Checks whether a given URL path matches one of the supported service prefix patterns
* and ends with the expected service suffix path.
*
* Currently method validates against DwC service patterns, supported patterns:
* - `/ui/<inbound-service-name>/v<version>/<suffix>`
* - `/<string>.<string>/external-ui/<inbound-service-name>/v<version>/<suffix>`
*
* The `<suffix>` (e.g. `odata/v4/myService`) must match exactly.
*
* @param path - The full request path to validate.
* @param expectedSuffixPath - The expected service path (e.g. `odata/v4/myService`).
* @returns `true` if the path matches one of the supported patterns and ends with the expected suffix.
*/
export declare function isMatchingServiceUri(path: string, expectedSuffixPath: string): boolean;
/**
* Get CAP CDS project environment config for project root.
*
* @param capProjectPath - project root of a CAP project
* @returns - environment config for a CAP project
*/
export declare function getCapEnvironment(capProjectPath: string): Promise<CdsEnvironment>;
/**
* Method to clear CAP CDS module cache for passed project path.
*
* @param projectRoot root of a CAP project.
* @returns True if cache cleared successfully.
*/
export declare function clearCdsModuleCache(projectRoot: string): Promise<boolean>;
/**
* Get absolute path to a resource.
*
* @param projectRoot - project root of a CAP project
* @param relativeUri - relative resource path.
* @returns {string} - absolute path.
*/
export declare const toAbsoluteUri: (projectRoot: string, relativeUri: string) => string;
/**
* Converts to referenced uri to be used in using statements.
*
* @param projectRoot - project root of a CAP project
* @param relativeUriFrom - relative uri of from directory
* @param relativeUriTo - relative uri of to directory
* @returns {Promise<string>} - reference uri
*/
export declare const toReferenceUri: (projectRoot: string, relativeUriFrom: string, relativeUriTo: string) => Promise<string>;
/**
* Clear cache of request to load global cds module.
*/
export declare function clearGlobalCdsModulePromiseCache(): void;
/**
* Retrieves the global CDS home path from the environment.
*
* Uses the output of `cds env --json` to determine the location of the global @sap/cds-dk installation.
*
* @returns {Promise<string | undefined>} The absolute path to the global CDS home directory, or undefined if not found.
*/
export declare function getGlobalCdsHomePath(): Promise<string | undefined>;
/**
* Method resolves cap service name for passed project root and service uri.
*
* @param projectRoot - project root
* @param datasourceUri - service uri
* @returns - found cap service name
*/
export declare function getCapServiceName(projectRoot: string, datasourceUri: string): Promise<string>;
/**
* Delete application from CAP project.
*
* @param appPath - path to the application in a CAP project
* @param [memFs] - optional mem-fs-editor instance
* @param [logger] - function to log messages (optional)
*/
export declare function deleteCapApp(appPath: string, memFs?: Editor, logger?: Logger): Promise<void>;
/**
* Check if cds-plugin-ui5 is enabled on a CAP project. Checks also all prerequisites, like minimum @sap/cds version.
* Overloaded function that returns detailed CAP plugin info.
*
* @param basePath - root path of the CAP project, where package.json is located
* @param [fs] - optional: the memfs editor instance
* @returns true: cds-plugin-ui5 and all prerequisites are fulfilled; false: cds-plugin-ui5 is not enabled or not all prerequisites are fulfilled
*/
export declare function checkCdsUi5PluginEnabled(basePath: string, fs?: Editor): Promise<boolean>;
/**
* Check if cds-plugin-ui5 is enabled on a CAP project. Checks also all prerequisites, like minimum @sap/cds version.
*
* @param basePath - root path of the CAP project, where package.json is located
* @param [fs] - optional: the memfs editor instance
* @param [moreInfo] if true return an object specifying detailed info about the cds and workspace state
* @returns false if package.json is not found at specified path or {@link CdsUi5PluginInfo} with additional info
*/
export declare function checkCdsUi5PluginEnabled(basePath: string, fs?: Editor, moreInfo?: boolean): Promise<boolean | CdsUi5PluginInfo>;
/**
* Check if cds-plugin-ui5 is enabled on a CAP project. Checks also all prerequisites, like minimum @sap/cds version.
*
* @param basePath - root path of the CAP project, where package.json is located
* @param [fs] - optional: the memfs editor instance
* @param [moreInfo] if true return an object specifying detailed info about the cds and workspace state
* @param {CdsVersionInfo} [cdsVersionInfo] - If provided will be used instead of parsing the package.json file to determine the cds version.
* @returns false if package.json is not found at specified path or {@link CdsUi5PluginInfo} with additional info
*/
export declare function checkCdsUi5PluginEnabled(basePath: string, fs?: Editor, moreInfo?: boolean, cdsVersionInfo?: CdsVersionInfo): Promise<boolean | CdsUi5PluginInfo>;
/**
* Get information about the workspaces in the CAP project.
*
* @param basePath - root path of the CAP project, where package.json is located
* @param packageJson - the parsed package.json
* @returns - appWorkspace containing the path to the appWorkspace including wildcard; workspaceEnabled: boolean that states whether workspace for apps are enabled
*/
export declare function getWorkspaceInfo(basePath: string, packageJson: Package): Promise<{
appWorkspace: string;
workspaceEnabled: boolean;
workspacePackages: string[];
}>;
/**
* Check if package.json has version or version range that satisfies the minimum version of @sap/cds.
*
* @param packageJson - the parsed package.json
* @returns - true: cds version satisfies the min cds version; false: cds version does not satisfy min cds version
*/
export declare function satisfiesMinCdsVersion(packageJson: Package): boolean;
/**
* Check if package.json has dependency to the minimum min version of @sap/cds,
* that is required to enable cds-plugin-ui.
*
* @param packageJson - the parsed package.json
* @returns - true: min cds version is present; false: cds version needs update
*/
export declare function hasMinCdsVersion(packageJson: Package): boolean;
//# sourceMappingURL=cap.d.ts.map