import EventEmitter from 'node:events'; import winston from 'winston'; import type ControllerManager from './controllers/index.ts'; import type { TFolderConfig, TFolderConfigFolders } from './folderConfig.ts'; import type AbstractModel from './modules/AbstractModel.ts'; import type BaseCli from './modules/BaseCli.ts'; import type { BaseModel, TBaseModel } from './modules/BaseModel.ts'; import Cache from './services/cache/Cache.ts'; import type HttpServer from './services/http/HttpServer.ts'; import type { I18n } from './services/i18n/I18n.ts'; interface AppCache { configs: Map; models: Map; modelConstructors: Map; modelPaths: { path: string; file: string; }[]; } export interface IApp { getConfig(configName: string): Record; getModel(modelName: string): AbstractModel['mongooseModel'] | false | TBaseModel; runCliCommand(commandName: string): Promise; updateConfig(configName: string, config: Record): Record; getI18nService(): Promise; foldersConfig: TFolderConfigFolders; events: EventEmitter; readonly cache: Cache; readonly logger: winston.Logger; httpServer: null | HttpServer; controllerManager: null | ControllerManager; frameworkFolder: string; documentation?: unknown[]; internalFilesCache: AppCache; } /** * Main framework class. */ declare class Server { #private; cli: null | BaseCli; config: TFolderConfig; cache: AppCache; cacheService: null | Cache; app: IApp; /** * Construct new server * @param {Object} config main config object * @param {Object} config.folders folders config * @param {String} config.folders.config path to folder with config files * @param {String} config.folders.models path to folder with moidels files * @param {String} config.folders.controllers path to folder with controllers files * @param {String} config.folders.locales path to folder with locales files * @param {String} [config.folders.emails] path to folder with emails files * @param {String} config.folders.commands path to folder with commands files * @param {String} config.folders.migrations path to folder with migrations files */ constructor(config: TFolderConfig); /** * Start server (http + init all http ralated functions) * @param {Function} callbackBefore404 code that should be executed before adding page 404 */ startServer(callbackBefore404?: () => Promise): Promise; /** * Do an initialization (config reading, etc) */ init({ isSkipModelInit, isSkipModelLoading, }?: { isSkipModelInit?: boolean | undefined; isSkipModelLoading?: boolean | undefined; }): Promise; /** * Load model and init them */ initAllModels(): Promise; getModelFilesPathsWithInheritance(): Promise<{ path: string; file: string; }[]>; /** * Add error logging on promise reject */ addErrorHandling(): void; /** * Return config from {configName} (file name) on config folder. * Support cache and updating confing into cache * Also will update config based on NODE_ENV. If config.js and config.production.js * and NODE_ENV is production then we will load base config (config.js) and the load * environment config (config.production.js) and overwrite base config options * @see updateConfig * @param {String} configName name on config file to load * @returns {Object} config object. Structure depends of config file */ getConfig(configName: string): Record; /** * Return or create new logger instance. This is a main logger instance */ getLogger(): winston.Logger; /** * Primary designed for tests when we need to update some configs before start testing * Should be called before any initialization was done * @TODO send event to all inited components to update config * @param {String} configName * @param {Object} config */ updateConfig(configName: string, config: Record): Record; getI18nService(): Promise; /** * Return model from {modelName} (file name) on model folder. * Support cache * @param {String} modelName name on config file to load */ getModel(modelName: string): AbstractModel['mongooseModel'] | TBaseModel | false; /** * Run cli command into framework (http, ws, etc) * @param {String} commandName name of command to load */ runCliCommand(commandName: string): Promise; /** * Get internal cache service */ getCache(): Cache; } export default Server;