import { Container } from 'inversify'; import { RouteBuilder, RouteDefinition, FilterDefinition } from './WebAppMeta'; import { RouteHandler } from './RouteHandler'; import { MethodMeta } from './MethodMeta'; import { RouteMetadata } from '@webpieces/core-util'; import { WpResponse, Service } from './Filter'; import { HttpFilter } from './FilterMatcher'; /** * FilterWithMeta - Pairs a resolved filter instance with its definition. * Stores both the DI-resolved filter and the metadata needed for matching. */ export declare class FilterWithMeta { filter: HttpFilter; definition: FilterDefinition; constructor(filter: HttpFilter, definition: FilterDefinition); } /** * RouteHandlerImpl - Concrete implementation of RouteHandler. * Wraps a resolved controller and method to invoke on each request. */ export declare class RouteHandlerImpl implements RouteHandler { private controller; private method; constructor(controller: Record, method: (this: unknown, requestDto?: unknown) => Promise); execute(meta: MethodMeta): Promise; } /** * RouteHandlerWithMeta - Pairs a route handler with its definition. * Stores both the handler (which wraps the DI-resolved controller) and the route metadata. * * We use unknown for the generic type since we store different TResult types in the same Map. * Type safety is maintained through the generic on RouteDefinition at registration time. */ export declare class RouteHandlerWithMeta { invokeControllerHandler: RouteHandler; definition: RouteDefinition; constructor(invokeControllerHandler: RouteHandler, definition: RouteDefinition); } /** * RouteBuilderImpl - Concrete implementation of RouteBuilder interface. * * Similar to Java WebPieces RouteBuilder, this class is responsible for: * 1. Registering routes with their handlers * 2. Registering filters with priority * * This class is explicit (not anonymous) to: * - Improve traceability and debugging * - Make the code easier to understand * - Enable better IDE navigation (Cmd+Click on addRoute works!) * * DI Pattern: This class is registered in webpiecesContainer via @provideFrameworkSingleton() * but needs appContainer to resolve filters/controllers. The container is set via * setContainer() after appContainer is created (late binding pattern). */ export declare class RouteBuilderImpl implements RouteBuilder { private routes; private filterRegistry; private container?; /** * Map for O(1) route lookup by method:path. * Used by both addRoute() and createRouteInvoker() for fast route access. */ private routeMap; /** * Create route key for consistent lookup. * Key format: "${METHOD}:${path}" (e.g., "POST:/search/item") */ private createRouteKey; /** * Set the DI container used for resolving filters and controllers. * Called by WebpiecesCoreServer after appContainer is created. * * @param container - The application DI container (appContainer) */ setContainer(container: Container): void; /** * Register a route with the router. * * Uses createRouteHandlerWithMeta() to create the handler, then stores it * in both the routes array and the routeMap for O(1) lookup. * * @param route - Route definition with controller class and method name */ addRoute(route: RouteDefinition): void; /** * Create RouteHandlerWithMeta from a RouteDefinition. * * Resolves controller from DI container ONCE and creates a handler that * invokes the controller method with the request DTO. * * This method is used by: * - addRoute() for production route registration * - createRouteInvoker() for test clients (via createApiClient) * * @param route - Route definition with controller class and method name * @returns RouteHandlerWithMeta containing the handler and route definition */ private createRouteHandlerWithMeta; /** * Register a filter with the filter chain. * * Resolves the filter from DI container and pairs it with the filter definition. * The definition includes pattern information used for route-specific filtering. * * @param filterDef - Filter definition with priority, filter class, and optional filepath pattern */ addFilter(filterDef: FilterDefinition): void; /** * Get all registered routes. * * @returns Map of routes with handlers and definitions, keyed by "METHOD:path" */ getRoutes(): RouteHandlerWithMeta[]; /** * Get all filters sorted by priority (highest priority first). * * @returns Array of FilterWithMeta sorted by priority */ getSortedFilters(): Array; /** * Cached filter definitions for lazy route setup. */ private cachedFilterDefinitions?; /** * Get filter definitions, computing once and caching. */ private getFilterDefinitions; /** * Setup a single route by creating its filter chain. * This is called lazily by createHandler() and getRouteService(). * * Creates a Service that wraps the filter chain and controller invocation. * The service is DTO-only and has no Express dependency. * * @param key - Route key in format "METHOD:path" * @param routeWithMeta - Route handler with metadata * @returns The service for this route */ createRouteHandler(routeWithMeta: RouteHandlerWithMeta): Service>; /** * Create an invoker function for a route (for testing via createApiClient). * Uses routeMap for O(1) lookup, sets up the filter chain ONCE, * and returns a Service that can be called multiple times without * recreating the filter chain. * * This method is called by WebpiecesServer.createApiClient() during proxy setup. * The returned Service is stored as the proxy method and invoked on each call. * * @param method - HTTP method (GET, POST, etc.) * @param path - URL path * @returns A Service that invokes the route */ createRouteInvoker(method: string, path: string): Service>; /** * Look up the RouteMetadata (incl. authMeta) for a registered route by method+path. * Used to build a MethodMeta for an in-process dispatch (e.g. a delivered cloud * task) so the filter chain sees the same routeMeta production HTTP would. * * @returns the route's RouteMetadata, or undefined if no route is registered. */ getRouteMeta(method: string, path: string): RouteMetadata | undefined; }