import type { IRouter } from 'express'; import type { IApp } from '../server.ts'; import type AbstractMiddleware from '../services/http/middleware/AbstractMiddleware.ts'; import Base from './Base.ts'; type MiddlewareWithParamsTuple = [ typeof AbstractMiddleware, Record ]; export type TMiddleware = Array; type RouteHandler = Function; type RouteObject = { handler: RouteHandler; description?: string; middleware?: TMiddleware | null; request?: (unknown & { fields: unknown; }) | null; query?: (unknown & { fields: unknown; }) | null; }; export type RouteParams = { [method: string]: { [path: string]: RouteObject | RouteHandler; }; }; /** * 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; router: IRouter; constructor(app: IApp, prefix: string, isExpressMergeParams?: boolean); /** * Parse middlewares to be an object. */ parseMiddlewares(middlewareMap: Map, httpPath: string): { name: string; method: string; path: string; fullPath: string; params: {}; relatedQueryParameters: import("yup").ObjectSchema<{}, import("yup").AnyObject, {}, "">; authParams: { name: string; type: string; in?: string; scheme?: string; description: string; }[]; MiddlewareFunction: typeof AbstractMiddleware; }[]; /** * 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;