UNPKG

@mini2/core

Version:

Mini Express Framework - Lightweight and modular Express.js framework with TypeScript support

102 lines 5.21 kB
import 'reflect-metadata'; import express, { type Express } from 'express'; import type { IRouter, RequestHandler } from 'express'; export type Method = 'get' | 'post' | 'put' | 'delete' | 'patch'; export type IValidation = { body?: any; params?: any; query?: any; }; export type IExtraData = Map<string, any>; export type ParameterSlot = 'req' | 'res' | 'next' | 'body' | 'query' | 'params'; export interface RouteOptions { method?: Method; path?: string; validations?: IValidation[]; permissions?: string[]; authenticated?: boolean; otherHttpMiddlewares?: RequestHandler[]; extraData?: IExtraData; name?: string; } export interface RouteDefinition { methodName: string; method?: Method; path?: string; name?: string; validations: IValidation[]; permissions: string[]; authenticated?: boolean; otherHttpMiddlewares: RequestHandler[]; extraData?: IExtraData; parameterIndices?: Partial<Record<ParameterSlot, number>>; } export interface RouteDefinitions { basePath: string; controllerName?: string; moduleName?: string; routes: RouteDefinition[]; } export interface IControllerClassConstructor { new (...args: any[]): any; __routeDefinitions?: RouteDefinitions; } export interface IController { path: string; name: string; moduleName: string; getRouteDefinition(methodName: string): RouteDefinition; getRouteDefinitions(): RouteDefinitions; } export declare class Controller implements IController { path: string; name: string; moduleName: string; routeDefinitions: RouteDefinitions; constructor(); getRouteDefinition(methodName: string): RouteDefinition; getRouteDefinitions(): RouteDefinitions; } export declare class RouteRegistry { private static getCtor; static getRouteDefinitions(target: any): RouteDefinitions; static setBasePath(constructor: IControllerClassConstructor, basePath: string, controllerName?: string, moduleName?: string): void; static getOrCreateRoute(target: any, methodName: string): RouteDefinition; static updateRoute(target: any, methodName: string, updates: Partial<RouteDefinition>): void; static setParameterIndex(target: any, methodName: string, slot: ParameterSlot, index: number): void; static getRoutes(target: any): RouteDefinition[]; static getBasePathOf(target: any): string; } export declare const keyOfPath: unique symbol; export declare const keyOfName: unique symbol; export declare const keyOfModuleName: unique symbol; export declare const keyOfRouteOptions: unique symbol; export declare const keyOfReq: unique symbol; export declare const keyOfRes: unique symbol; export declare const keyOfNext: unique symbol; export declare const keyOfBody: unique symbol; export declare const keyOfQuery: unique symbol; export declare const keyOfParams: unique symbol; export declare function controller(path: string, name?: string, moduleName?: string): <T extends { new (...args: any[]): Controller; }>(constructor: T) => T; export declare function httpMethod(newOptions: RouteOptions): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void; export declare function get(path: string, name?: string): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void; export declare function post(path: string, name?: string): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void; export declare function put(path: string, name?: string): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void; export declare function del(path: string, name?: string): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void; export declare function patch(path: string, name?: string): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void; export declare function validate(options: IValidation | IValidation[]): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void; export declare function authenticated(value?: boolean): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void; export declare function authorized(value: string | string[]): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void; export declare function middleware(mw: RequestHandler): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void; export declare function custom<T>(key: string, value: T): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void; export declare function req(): (t: any, k: string, i: number) => void; export declare function res(): (t: any, k: string, i: number) => void; export declare function next(): (t: any, k: string, i: number) => void; export declare function body(): (t: any, k: string, i: number) => void; export declare function query(): (t: any, k: string, i: number) => void; export declare function params(): (t: any, k: string, i: number) => void; export declare function buildRouterFromController(controllerInstance: IController): IRouter; export declare function buildApp(app: Express, controllers: IController[]): express.Express; //# sourceMappingURL=rest.d.ts.map