import { EventEmitter } from 'events'; import { TokenManager } from './TokenManager'; import { Database } from './Database'; import { Handler } from './Handler'; import { IConfig } from './IConfig'; import { Command } from 'commander'; import { IAuthTokenData } from '@arashi/token'; import { BaseLogger } from '@arashi/logger'; export interface IStormCLIArgs { bind?: string; port?: number; authentication_header?: string; configFile?: string; localConfigFile?: string; custom: Record; } /** * Main entry point for the Application. Should be extended and have the abstract methods implemented. */ export declare abstract class Application extends EventEmitter { private $logger; private $name; /** * Path to the config directory. * This is used as a fallback and it will be expected that * bt-config.json and bt-local-config.json are found. */ private $configDir; /** * Path to a bt-config.json file */ private $configPath; /** * Path to a bt-local-config.json file */ private $localConfigPath; private $config; private $tokenManager; private $server; private $db; private $socket; private $program; private $usingDeprecatedConfigPath; /** * * @param name The application name * @param configPath @deprecated The directory where bt-config.json and bt-local-config.json can be found. Defaults to current working directory. */ constructor(name: string, configPath?: string); start(): Promise; private $load; protected _initialize(config: TConfig): Promise; protected _createLogger(config: TConfig): BaseLogger; protected _initLogger(config: TConfig): Promise; private $connectCW; private $validateCWConfig; getLogger(): BaseLogger; getPort(): number; getVersion(): string; protected _getVersion(): string; private $getVersionString; private $buildArgOptions; protected _buildArgOptions(program: Command): void; getProgram(): Command; /** * Override this method to map CLI args to customConfig * @param args */ getConfigFromCLIArgs(args: any): Record; /** * The maximum size limit for incoming requests that this service needs to handle. */ getRequestSizeLimit(): number; private $attachHandlers; /** * * @param path The URL API path. E.g. /api/myService/myCommand/ * @param Handler */ attachHandler(path: string, handler: Handler): void; attachHandlerInstance(path: string, handler: Handler): void; close(): Promise; protected _closeDatabase(): Promise; protected _closeSocket(): Promise; /** * Subclasses are expected to attach the API handlers for their service. This will be invoked during application startup. * @returns Promise */ protected abstract _attachHandlers(): Promise; /** * @deprecated Supply the configs via --config and --local-config arguments * * @param path The directory path that contains bt-config.json and bt-local-config.json */ loadConfig(path: string): Promise; private $loadConfig; getConfigFilePath(): string; getLocalConfigFilePath(): string; private $getLocalConfigFilePath; private $getConfigFilePath; /** * @returns the application name */ getName(): string; private $getLogger; /** * @returns the config object. */ getConfig(): TConfig; /** * @returns true if the Application should bind to an IP address */ shouldListen(): boolean; /** * Invoked once the config has been loaded and ready to be used. * * @param config The config object (as defined in bt-config.json/bt-local-config.json) */ protected _onConfigLoad(config: TConfig): void; /** * Sets the TokenManager to be used for authentication. * @param tokenManager */ setTokenManager(tokenManager: TokenManager): void; /** * @returns the token manager */ getTokenManager(): TokenManager; /** * @returns the database pool. This will need to be casted based on your preferred database dialect. */ getDB(): Database; /** * @returns command line arguments */ getCmdLineArgs(): IStormCLIArgs; /** * Subclasses are expected to override this to configure their database setup, if the service uses a database. * @param config The bt-config object */ protected _initDB(config: TConfig): Promise>; protected _onBeforeReadyAsync(): Promise; /** * Invoked when the application is considered ready for operation. */ protected _onReady(): void; }