UNPKG

honestjs

Version:

HonestJS - a modern web framework built on top of Hono

173 lines (172 loc) 6.09 kB
import type { ControllerOptions, FilterType, GuardType, MiddlewareType, ModuleOptions, ParameterMetadata, PipeType, RouteDefinition } from '../interfaces'; import type { Constructor } from '../types'; /** * Available component types that can be registered at different levels in the application * Each type corresponds to a specific aspect of request processing */ export type ComponentType = 'middleware' | 'guard' | 'pipe' | 'filter'; /** * Union type of all possible component instances * Represents any type of component that can be registered in the application */ export type ComponentInstance = MiddlewareType | GuardType | PipeType | FilterType; /** * Maps component type identifiers to their specific instance types * Used for type-safe component registration and retrieval */ export interface ComponentTypeMap { middleware: MiddlewareType; guard: GuardType; pipe: PipeType; filter: FilterType; } /** * Central registry for managing application metadata * Stores and provides access to: * - Route definitions and controller configurations * - Service and module registrations * - Parameter metadata and context indices * - Component registrations at global, controller, and handler levels */ export declare class MetadataRegistry { /** * Stores route definitions for each controller * Maps controller classes to their route configurations */ private static readonly routes; /** * Stores base paths for controllers * Maps controller classes to their route prefixes */ private static readonly controllers; /** * Stores configuration options for controllers * Includes settings like versioning and prefix options */ private static readonly controllerOptions; /** * Registry of service classes * Used for dependency injection and lifecycle management */ private static readonly services; /** * Stores configuration options for modules * Includes imports, exports, providers, and controllers */ private static readonly modules; /** * Stores parameter metadata for controller methods * Used for parameter transformation and validation */ private static readonly parameters; /** * Stores indices of context parameters in controller methods * Used for optimizing context injection */ private static readonly contextIndices; /** * Registry for global-level components * Components registered here apply to all routes */ private static readonly global; /** * Registry for controller-level components * Components registered here apply to all routes in a specific controller */ private static readonly controller; /** * Registry for handler-level components * Components registered here apply to specific route handlers */ private static readonly handler; /** * Gets all route definitions for a controller * @param controller - The controller class to get routes for * @returns Array of route definitions for the controller */ static getRoutes(controller: Constructor): RouteDefinition[]; /** * Set routes for a controller */ static setRoutes(controller: Constructor, routes: RouteDefinition[]): void; /** * Add a route to a controller */ static addRoute(controller: Constructor, route: RouteDefinition): void; /** * Get controller path */ static getControllerPath(controller: Constructor): string; /** * Set controller path */ static setControllerPath(controller: Constructor, path: string): void; /** * Get controller options */ static getControllerOptions(controller: Constructor): ControllerOptions; /** * Set controller options */ static setControllerOptions(controller: Constructor, options: ControllerOptions): void; /** * Check if class is a service */ static isService(service: Constructor): boolean; /** * Add a service */ static addService(service: Constructor): void; /** * Get all services */ static getAllServices(): Set<Constructor>; /** * Get module options */ static getModuleOptions(module: Constructor): ModuleOptions | undefined; /** * Set module options */ static setModuleOptions(module: Constructor, options: ModuleOptions): void; /** * Get parameter metadata */ static getParameters(controller: Constructor): Map<string | symbol, ParameterMetadata[]>; /** * Set parameter metadata */ static setParameterMap(controller: Constructor, params: Map<string | symbol, ParameterMetadata[]>): void; /** * Get context indices */ static getContextIndices(controller: Constructor): Map<string | symbol, number>; /** * Set context indices */ static setContextIndices(controller: Constructor, indices: Map<string | symbol, number>): void; /** * Register a component at the global level */ static registerGlobal<T extends ComponentType>(type: T, component: ComponentTypeMap[T]): void; /** * Get all global components of a specific type */ static getGlobal<T extends ComponentType>(type: T): Set<ComponentTypeMap[T]>; /** * Register a component at the controller level */ static registerController<T extends ComponentType>(type: T, controller: Constructor, component: ComponentTypeMap[T]): void; /** * Get all controller-level components of a specific type for a controller */ static getController<T extends ComponentType>(type: T, controller: Constructor): ComponentTypeMap[T][]; /** * Register a component at the handler level */ static registerHandler<T extends ComponentType>(type: T, handlerKey: string, component: ComponentTypeMap[T]): void; /** * Get all handler-level components of a specific type for a handler */ static getHandler<T extends ComponentType>(type: T, handlerKey: string): ComponentTypeMap[T][]; }