inceptum
Version:
hipages take on the foundational library for enterprise-grade apps written in NodeJS
78 lines (77 loc) • 3.04 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;
shutdownTimer?: number;
}
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;
/**
* Register services or controllers with Inceptum
* Note that we are using "npm globby" internally for glob matching.
*
* Globs are disabled by default. Pass isGlob=true to enable glob matching
*
* Globs will be automatically activated if the "patterns" parameter is an array of strings,
* or if it contains magic characters (eg: * ? { })
*
* @param {string|Array<string>} patterns - path as a relative path or as glob pattern(s). See options for more details
* @param {Object} [options] - options object for enabling and configuring glob matching
* @param {boolean} [options.isGlob=false] - pass true to treat the path as a glob
* @param {Object} [options.globOptions] - options to pass to globby
*/
addDirectory(patterns: string | Array<string>, options?: {
isGlob: boolean;
globOptions: Object;
}): void;
register(...plugins: PluginImplemenation[]): void;
getRegisteredPluginNames(): string[];
hasRegisteredPlugin(name: string): boolean;
private runLifecycleMethodOnPlugins;
start(): Promise<any>;
stop(): Promise<any>;
getContext(): Context;
getConfig(key: any, defaultValue: any): any;
hasConfig(key: any): boolean;
}