import { THookCallback } from './hooks'; import { IService } from './services'; import { IModule, IModuleConfig } from './modules'; import { IConfig } from './config'; export declare class Kapp { /** * @property The application's modules manager. */ private _modulesManager; /** * @property Contains all the services of this application. */ private _services; /** * @property The application configuration. */ private _config; /** * @property The main app hooks manager. Mainly used for lifecycle events. */ private _hooksManager; /** * @property Top-level application event emitter. */ private _appEvents; /** * @property The absolute path to the application directory. */ private _path; /** * @property A flag that defines if the app have been initialized. */ private _initialized; /** * Gets the absolute path the app directory. */ get path(): string; /** * Creates a copy of the application config object, and returns it. To set or get configuration values, you should use setConfig() or * config() methods. */ get configObject(): IConfig; /** * Class constructor. * @param appDirectory The path to your application directory. */ constructor(appDirectory: string); /** * Loads all application modules, and their configuration. */ load(): Promise; /** * Initializes the application and loads all core systems (modules, services, ...). */ init(): Promise; /** * Starts the application. */ start(): Promise; /** * Stops the application. * @param errorCode The eventual error code in case you need to force the application to stop. If null given, let the process ends * itself. Otherwise, use process.exit() to force the application to stop. Note that if you need to use this, you might forgot to * stop a service at the right time. Listen for the "stop" hook to stop any process without having to force it! */ stop(errorCode?: number): Promise; /** * Shortcut for calling load(), init() and start(). */ run(): Promise; /** * Adds a module to the application, without using a module.json file. * @param path The absolute path to the module directory. * @param config The module configuration. * @throws {ModuleException} Thrown if another module of the same name exists. */ addModule(moduleDirectory: string, name: string, options: Omit): Promise; /** * Gets the module of the given name. * @param name The name of the module you want to get. * @returns Returns the found module path and configuration, or null if there's no module of the given name. */ module(name: string): IModule; /** * Performs an operation for each loaded modules. * @param callback The method to execute for each module. */ forEachModule(callback: (path: string, config: IModuleConfig) => void | Promise): Promise; /** * Registers an instance of a service. If the app has already been initialized, the given service instance is initialized instantly. This * means that if the app is not initialized, this operation is synchronous, but it becames asynchronous if the service needs to be * initialized. * @param name The name of the service to register. * @param instance The instance of the service. * @throws {ServiceException} Thrown if the application already has a service with the given name. */ addService(name: string, instance: IService): Promise; /** * Alias of addService(). * Registers an instance of a service. If the app has already been initialized, the given service instance is initialized instantly. This * means that if the app is not initialized, this operation is synchronous, but it becames asynchronous if the service needs to be * initialized. * @param name The name of the service to register. * @param instance The instance of the service. * @throws {ServiceException} Thrown if the application already has a service with the given name. */ use: (name: string, instance: IService) => Promise; /** * Gets a registered service by its name. * @template TService Defines the expected type of the service you want to get. * @param name The name of the service you want to get. If null, get the service by the template type. * @returns Returns the found service instance, otherwise null. */ service(name?: string): TService; /** * Adds the given configuration object to the existing config. * @param config The path to a config file, or a config object to assign. * @param replace If true, replaces or extends the existing configuration properties with the same name. If false, just overrides the * existing config properties, without adding new ones. * @param source If given and the config is a file path, resolves the config file relative path from this source path. * @param ignoreMissingFile If true, this method won't throw an error if the config file at the given path doesn't exist. * @throws {ConfigException} Thrown if the config file at the given path can't be found (and ignoreMissingFile is set to false). * @throws {ConfigException} Thrown if the config file content at the given path can't be read. */ setConfig(config: string | IConfig, replace?: boolean, source?: string, ignoreMissingFile?: boolean): void; /** * Gets the value of a configuration key. * @template TConfigValue Defines the type of the value to get. * @template TDefaultValue Defines the type of the default value. * @param key The name of the configuration property to get. This can also be a "property scheme". For example, if you pass * "auth.secretKey", this method will get the "secretKey" value of "auth" property if it exists. * @param defaultValue If given, and the named property doesn't exist, returns this value. */ config(key: string, defaultValue?: TDefaultValue): TConfigValue | TDefaultValue; /** * Adds a callback method to the named hook. * @param name The name of the hook you want to add a callback. * @param callback The callback method to execute when the named hook is used. * @param order The default order of the callback. The lowest the value, the first the callback is called. * @throws {HookException} Thrown if the named hook doesn't exist. */ hook(hookName: string, callback: THookCallback, order?: number): void; /** * Listen for an event from the top-level application event emitter. * @param eventName The name of the event to listen. * @param callback Method to call when the named event is triggered. */ on(eventName: string | symbol, callback: (...params: unknown[]) => void): void; /** * Emits the named event from the top-level application event emitter. * @param eventName The name of the event to trigger. * @param params Eventual params to send to the listeners. */ emit(eventName: string | symbol, ...params: unknown[]): void; /** * Initializes all app services. */ private _initRegisteredServices; /** * Initializes the given service. * @param name The name of the service you want to initialize. * @param instance The instance of the service to initialize. * @throws {InitializationException} Thrown if the named service cannont be initialized, probably because of an error from that service. */ private _initService; } export default Kapp;