import type AbstractController from '../modules/AbstractController.ts'; import Base from '../modules/Base.ts'; import type { IApp } from '../server.ts'; import type { HandlerEntry, HttpMethod, MiddlewareEntry, RouteNode } from '../services/http/routing/RouteNode.ts'; /** * Class does autoloading a http controllers */ declare class ControllerManager extends Base { #private; controllers: Record; constructor(app: IApp); /** * Register a controller explicitly. Returns the constructed instance. * Builds a `RouteNode` subtree from the controller's `routes` getter and * `static middleware` Map, wraps handlers with validation, and registers * with the `RouteRegistry`. For late registration (after `startServer` * finishes) use `Server.startServer`'s `callbackBefore404` hook. */ registerController(ControllerClass: T, prefix?: string, options?: { skipWrap?: boolean; }): InstanceType; /** * Register an already-constructed controller instance: store it, build its * `RouteNode` subtree (from `routes` + the static middleware Map), optionally * wrap handlers with validation, and register with the `RouteRegistry`. * * Reads the instance into a `ControllerSubtreeSpec` (`#specFromInstance`) and * assembles the tree via the shared `buildSubtreeFromSpec`. Codegen reaches the * same assembler directly from parsed source (no instance) — see * `codegen/astSpec.ts` — so tree/middleware semantics live in one place. */ registerControllerInstance(instance: T, prefix?: string, options?: { skipWrap?: boolean; }): T; /** * Discover and import every controller module — framework-internal plus the * user's folder, with user overrides winning on filename collision (handled by * `getFilesPathWithInheritance`). Returns each class with its folder prefix. * * The shared "load" step that does not instantiate — runtime boot * (`initControllers`) and codegen both drive the per-class loop from this. * Imports run in parallel; the returned order is the index-first sort, so * registration is deterministic. */ loadControllerClasses(): Promise<{ ControllerClass: typeof AbstractController; prefix: string; }[]>; /** * Auto-load controllers (see `loadControllerClasses`) and register each one * with a real instance. * * `options.skipWrap` (codegen-only): build the registry tree without wrapping * handlers with validation — skips middleware instantiation, which avoids side * effects (Redis clients, timers) in introspection commands like * `generatetypes`. */ initControllers(options?: { skipWrap?: boolean; }): Promise; static get loggerGroup(): string; } /** * The plain, instance-free description of a controller's subtree: handlers to * place and middleware scopes to attach, both already path-converted and * (for middleware) normalized. The runtime builds this from a controller * instance (`#specFromInstance`); the codegen AST front-end builds the same * shape from parsed source — so both feed one assembler with zero drift. * * Paths are INTERNAL syntax (`*splat`, not `{*splat}`); `method` is upper-case * (`'ALL'` for path-only middleware scopes). */ export interface ControllerSubtreeSpec { ctrlName: string; handlers: { method: HttpMethod; path: string; entry: HandlerEntry; }[]; middleware: { method: HttpMethod | 'ALL'; path: string; entries: MiddlewareEntry[]; }[]; } /** * Assemble a `RouteNode` subtree from a `ControllerSubtreeSpec`: place every * handler, then attach every middleware scope (handlers first, so middleware * attachments find them). This is the single home of tree/scope semantics — * runtime and codegen both reach it through here. */ export declare function buildSubtreeFromSpec(spec: ControllerSubtreeSpec, onWarn?: (msg: string) => void): RouteNode; /** * Controller discovery order: index files first (so root-level * routes/middleware accumulate before nested ones), and among index files the * shallower one first (root `index` before nested `sub/index`). Consistent and * antisymmetric per ECMA-262; non-index pairs compare equal and rely on * `Array.prototype.sort` stability to keep discovery order. */ export declare function compareControllerLoadOrder(a: { file: string; }, b: { file: string; }): number; /** * `'POST/login'` → method=POST,path=/login · `'/login'` → method=ALL,path=/login * * When the key looks like `METHOD/path` but the method isn't recognized * (likely a typo, e.g., `'PATC/login'`), returns `unknownMethod` so the * caller can warn instead of silently treating the whole key as a path. */ export declare function parseScopeKey(key: string): { method: HttpMethod | 'ALL'; path: string; unknownMethod?: string; }; /** `{*splat}` → `*splat`. Other syntax stays as-is. */ export declare function convertPathSyntax(p: string): string; export default ControllerManager;