@megaorm/cli
Version:
This package allows you to communicate with MegaORM via commands directly from the command line interface (CLI).
53 lines (52 loc) • 2.52 kB
TypeScript
/**
* Custom error class for handling errors related to model operations.
*/
export declare class ModelHandlerError extends Error {
}
/**
* This class provides functionality for adding, and removing model files
*
*/
export declare class ModelHandler {
/**
* The absolute path to the assets directory.
*/
private assets;
/**
* Instantiates a new ModelHandler.
*/
constructor();
/**
* Collects the absolute paths of model files from the specified directory.
*
* @param path The directory path from which to collect model files.
* @param map A boolean indicating whether to include mapped files (e.g., `.js.map`) in the resulting paths.
* @returns A promise that resolves with an array of absolute paths to valid model files.
* @throws `ModelHandlerError` if there is an issue collecting the files or if an invalid model file is encountered.
*/
private collectPaths;
/**
* Creates a new model file in the specified path.
*
* This method creates a new file for the specified table name in the given directory path.
* You can choose to create a TypeScript file or a JavaScript file based on the provided boolean flag.
*
* @param name The snake_case table name for which the model is created.
* @param path The directory path where the model file will be created.
* @param ts A boolean indicating whether to create a TypeScript file (`true`) or a JavaScript file (`false`).
* @returns A promise that resolves with a success message indicating the path of the created model file.
* @throws `ModelHandlerError` If the table name is invalid, the path is empty, or if any errors occur during file operations.
* @note The table name must be a snake_case table name, e.g., users, category_product.
*/
add(name: string, path: string, ts?: boolean): Promise<string>;
/**
* Removes the model associated with the given table name from the specified folder path.
*
* @param name The snake_case table name whose associated model is to be removed.
* @param path The directory path where the model files are located.
* @returns A promise that resolves with a success message indicating how many model files were removed.
* @throws `ModelHandlerError` If the table name is invalid, the path is empty.
* @note The table name must be a snake_case table name, e.g., users, category_product.
*/
remove(name: string, path: string): Promise<string>;
}