hivest-js
Version:
A simple, fast and minimalist framework for Node.js that allows you to create modular applications with dependency injection using decorators
126 lines • 4.03 kB
TypeScript
import express from 'express';
import 'reflect-metadata';
import { EventManager } from '../event-manager';
export type AppProviderType = {
key: string;
provide: any;
} | {
key: string;
useValue: any;
} | (new (...args: any[]) => any);
export type AppControllerType = new (...args: any[]) => {
[]: any;
};
/**
* Main application module class that handles dependency injection,
* route registration, and module composition
*/
export declare class AppModule {
readonly options: {
path?: string;
providers?: AppProviderType[];
controllers?: AppControllerType[];
imports?: (AppModule | (new () => AppModule))[];
};
private app;
private initialized;
private bootstrapped;
private parentModule?;
private allProviders;
private eventManager;
constructor(options: {
path?: string;
providers?: AppProviderType[];
controllers?: AppControllerType[];
imports?: (AppModule | (new () => AppModule))[];
});
/**
* Get the Express application instance
*/
getApp(): express.Application;
/**
* Get the event manager instance
*/
getEventManager(): EventManager;
/**
* Get all providers including parent module providers (recursive)
* Uses the Composite pattern to gather providers from the module hierarchy
*/
private getAllProviders;
/**
* Share providers from parent module to this child module
* This allows child modules to access parent module providers
*/
shareParentProviders(parentProviders: AppProviderType[]): void;
/**
* Register a provider in the dependency injection container
* Supports class providers, value providers, and smart providers
*/
private registerProvider;
/**
* Register all providers in the dependency injection container
* Uses the Strategy pattern to handle different provider types
*/
registerAllProviders(): void;
/**
* Check if a controller is marked as middleware
*/
private isMiddlewareController;
/**
* Check if a controller is marked as error handler middleware
*/
private isErrorHandlerController;
/**
* Process and register a single controller item (route, middleware, or error handler)
* Uses the Strategy pattern to handle different item types
*/
private processControllerItem;
/**
* Register a route in the Express application
*/
private registerRoute;
/**
* Register a middleware in the Express application
*/
private registerMiddleware;
/**
* Register an error handler in the Express application
*/
private registerErrorHandler;
/**
* Process and register all controllers from a module
* Uses the Template Method pattern to process controllers consistently
* Now automatically detects and processes middleware classes and error handlers
*/
private processControllers;
/**
* Ensure all methods without decorators in a middleware controller are treated as middleware
*/
private ensureMiddlewareMethods;
/**
* Bootstrap imported modules (parent modules)
* Uses the Composite pattern to handle module hierarchy
*/
private bootstrapImportedModules;
/**
* Process controllers from imported modules
* Uses the Visitor pattern to process external module controllers
*/
private processImportedModuleControllers;
/**
* Bootstrap the application module
* Orchestrates the entire initialization process using multiple patterns
*/
bootstrap(): Promise<this>;
/**
* Bootstrap child modules without re-registering providers
* This is used by child modules to avoid duplicate provider registration
*/
bootstrapChild(): Promise<this>;
/**
* Start the HTTP server
* Ensures proper initialization order
*/
listen(port: number): Promise<this>;
}
//# sourceMappingURL=module.d.ts.map