confinode
Version:
Node application configuration reader
80 lines (79 loc) • 2.42 kB
TypeScript
import Loader from '../Loader';
/**
* Types of available requests made by from generator function to caller.
*/
declare const enum RequestType {
IsFolder = 0,
FileExists = 1,
FolderContent = 2,
LoadConfigFile = 3
}
interface RequestIsFolder {
request: RequestType.IsFolder;
payload: string;
}
/**
* Create a request for if given parameter is a folder.
*
* @param path - The path to test.
* @returns The request.
*/
export declare function requestIsFolder(path: string): RequestIsFolder;
interface RequestFileExists {
request: RequestType.FileExists;
payload: string;
}
/**
* Create a request for if the given parameter is an existing file.
*
* @param file - The file to test.
* @returns The request.
*/
export declare function requestFileExits(file: string): RequestFileExists;
interface RequestFolderContent {
request: RequestType.FolderContent;
payload: string;
}
/**
* Create a request for the content of the folder given as parameter.
*
* @param folder - The folder to read.
* @returns The request.
*/
export declare function requestFolderContent(folder: string): RequestFolderContent;
interface RequestLoadConfigFile {
request: RequestType.LoadConfigFile;
payload: {
filePath: string;
loader: Loader;
};
}
/**
* Create a request for the configuration file content loading.
*
* @param filePath - The path of the file to load.
* @param loader - The loader to use.
* @returns The request.
*/
export declare function requestLoadConfigFile(filePath: string, loader: Loader): RequestLoadConfigFile;
/**
* All available requests.
*/
export declare type Request = RequestIsFolder | RequestFileExists | RequestFolderContent | RequestLoadConfigFile;
/**
* Execute a function, given as a generator, used asynchronously.
*
* @param stepRun - The function to execute. The function is a generator which may stop to request some
* information.
* @returns The return value of the given function.
*/
export declare function asyncExecute<R>(stepRun: Generator<Request, R, any>): Promise<R>;
/**
* Execute a function, given as a generator, used synchronously.
*
* @param stepRun - The function to execute. The function is a generator which may stop to request some
* information.
* @returns The return value of the given function.
*/
export declare function syncExecute<R>(stepRun: Generator<Request, R, any>): R;
export {};