import type { IApp } from '../server.ts'; import type AbstractMiddleware from '../services/http/middleware/AbstractMiddleware.ts'; import type { BodyParsingMode } from '../services/http/routing/RouteNode.ts'; import type { RequestContentTypeMap } from '../services/validate/contentType.ts'; import type { StandardSchemaV1 } from '../services/validate/types.ts'; import Base from './Base.ts'; type MiddlewareWithParamsTuple = readonly [ typeof AbstractMiddleware, Record ]; /** * The type TypeScript infers for an inline `[Middleware, params]` entry inside * an unannotated derived `routes` getter. Derived getters do not receive a * contextual return type from the base getter, so the tuple widens to an array * before override compatibility is checked. The exact tuple remains accepted * for explicitly typed values; this authoring-boundary form accepts the same * runtime shape after that unavoidable widening. */ type InferredMiddlewareWithParams = ReadonlyArray>; export type TMiddleware = Array; type RouteHandler = Function; type RouteObject = { handler: RouteHandler; description?: string; middleware?: TMiddleware | null; /** * Body schema. Either a single Standard Schema (validates any body), or a * content-type map (`{ 'application/json': schema, 'multipart/form-data': * schema }`) validated by the request's `Content-Type` — mirrors OpenAPI's * `requestBody.content`. Media-type matching is case-insensitive and ignores * parameters (`; charset=...`). With a map, `req.appInfo.request` is a * discriminated union keyed by a reserved `contentType` field — it holds the * matched media type and overwrites any body field of the same name, so do * not declare a schema field named `contentType`. */ request?: StandardSchemaV1 | RequestContentTypeMap | null; query?: StandardSchemaV1 | null; /** * Path-parameter schema. Validates and coerces the `:name` segments the same * way `request` handles the body: the validated output lands on * `req.appInfo.params`, a failure is a 400 with the standard error shape, and * raw `req.params` keeps its Express string values. Route-level only — * middleware do not contribute param schemas. */ params?: StandardSchemaV1 | null; /** * Per-route body parsing mode. Only `'parsed'` (the default) takes effect; * `'raw'` and `'none'` are reserved, not implemented yet, and currently do * nothing (the parser runs globally). See {@link BodyParsingMode}. */ bodyParsing?: BodyParsingMode; }; export type RouteParams = { [method: string]: { [path: string]: RouteObject | RouteHandler; }; }; /** * Convert a physical controller-folder prefix into its URL prefix. A fully * parenthesized segment is a route-transparent organizational group: * `(group)/admin` becomes `admin`. Both runtime loading and AST codegen call * the default-path helper below, so the convention cannot drift between them. */ export declare function controllerRoutePrefix(prefix: string): string; /** * Controller-file identity for framework inheritance. Route-group directory * segments are organizational, so `(group)/Auth.ts` must override the same * framework controller as root `Auth.ts`. This affects override comparison * only; generated files and source discovery keep their physical grouped path. */ export declare function controllerOverridePath(relativePath: string): string; /** * The default mount segment for a controller: `ClassName`, prefixed by the * route-bearing folders when nested (`admin/Users.ts` → `Admin/Users`). Exported * so codegen computes the same mount path as the runtime instance method below * — the two must never drift on where a controller mounts (see codegen doc 06). */ export declare function controllerConstructorName(prefix: string, className: string): string; /** Default HTTP mount path for a controller that doesn't override `getHttpPath`. */ export declare function defaultControllerHttpPath(prefix: string, className: string): string; /** * Abstract controller. You should extend any controller from them. * Place you cintroller into controller folder and it be inited in auto way. * By default name of route will be controller name not file name. But please name it in same ways. * You can overwrite base controllers byt creating controllers with tha same file name (yes file name, not class name) * In most cases you will want to have a 'home' route that not include controller name. For this case please check ' getHttpPath' */ declare class AbstractController extends Base { prefix: string; constructor(app: IApp, prefix: string); /** * Object with routes. Routes relative to controller * @example * return { * post: { * "/someUrl": { * handler: this.postSomeUrl, * request: yup.object().shape({ * count: yup.number().max(100)required(), * }) * } * }, * }; */ get routes(): RouteParams; /** * Array of middlewares to append for route * You should provide path relative to controller and then array of middlewares to apply. * Order is matter. * Be default path apply to ANY' method, but you can preattach 'METHOD' into patch to scope patch to this METHOD * @example * return new Map([ * ['/{*splat}', [GetUserByToken]] // for any method for this controller * ['POST/', [Auth]] // for POST method * ['/superSecretMethod', [OnlySuperSecretUsers]] // route with ANY method * ['PUT/superSecretMathod', [OnlySuperSecretAdmin]] // route with PUT method * ]); */ static get middleware(): Map; /** * Get constructor name that can include preix */ getConstructorName(): string; /** * Get http path with inheritance of path */ getHttpPath(): string; static get loggerGroup(): string; } export default AbstractController;