inceptum
Version:
hipages take on the foundational library for enterprise-grade apps written in NodeJS
58 lines (57 loc) • 2.06 kB
TypeScript
import { Context } from '../ioc/Context';
import { Logger } from '../log/LogManager';
import { ConfigAdapter } from '../config/ConfigProvider';
export declare type PluginLifecycleMethodName = 'willStart' | 'didStart' | 'willStop' | 'didStop';
export declare type PluginLifecycleMethod = (app: BaseApp, pluginContext?: Map<String, any>) => Promise<void> | void;
export declare type PluginType = {
[method in PluginLifecycleMethodName]: PluginLifecycleMethod;
};
export interface Plugin {
name: string;
willStart?: PluginLifecycleMethod;
didStart?: PluginLifecycleMethod;
willStop?: PluginLifecycleMethod;
didStop?: PluginLifecycleMethod;
}
export interface PluginWithWillStart {
willStart: PluginLifecycleMethod;
}
export interface PluginWithDidStart {
didStart: PluginLifecycleMethod;
}
export interface PluginWithWillStop {
willStop: PluginLifecycleMethod;
}
export interface PluginWithDidStop {
didStop: PluginLifecycleMethod;
}
export interface PluginNameable {
name: string;
}
export declare type PluginImplementsAtLeastOneMethod = PluginWithWillStart | PluginWithDidStart | PluginWithWillStop | PluginWithDidStop;
export declare type PluginImplemenation = PluginNameable & PluginImplementsAtLeastOneMethod;
export interface AppOptions {
logger?: Logger;
config?: ConfigAdapter;
}
export declare type PluginContext = Map<String | Symbol, any>;
export default class BaseApp {
protected logger: Logger;
protected context: Context;
protected appName: string;
protected plugins: PluginImplemenation[];
protected pluginContext: PluginContext;
/**
* Creates a new Inceptum App
*/
constructor(options?: AppOptions);
use(...plugins: PluginImplemenation[]): void;
addDirectory(path: any): void;
register(...plugins: PluginImplemenation[]): void;
private runLifecycleMethodOnPlugins(method);
start(): Promise<any>;
stop(): Promise<any>;
getContext(): Context;
getConfig(key: any, defaultValue: any): any;
hasConfig(key: any): boolean;
}