@celosiajs/core
Version:
CelosiaJS Core. A framework for REST API based on Express.js
161 lines (160 loc) • 10.8 kB
TypeScript
import { CelosiaRequest, Controller, MergeMiddlewaresOutput, Middleware, MiddlewareArray, NoInputMiddleware, ValidateController, ValidateControllerWithoutBody, ValidateMiddlewares } from '..';
/**
* Descendant routers will not inherit their parent's options.
*/
export interface CelosiaRouterOptions {
/**
* When `false` trailing slashes are optional.
*
* @default false
*/
strictTrailingSlashes?: boolean;
/**
* When `true` the routing will be case sensitive.
*
* @default false
*/
caseSensitive?: boolean;
/**
* When `true` any `request.params` passed to the router will be merged into the router's `request.params`.
*
* @default false
*/
mergeParams?: boolean;
}
/**
* Descendant routers will not inherit their parent's options.
*/
export interface CelosiaRouterConstructorOptions<Strict extends boolean = true> extends CelosiaRouterOptions {
strict: Strict;
}
/**
* Group router will only their direct parent's options.
*/
export type CelosiaRouterGroupCallback<Strict extends boolean> = (router: CelosiaRouter<Strict>) => void;
/**
* Descendant routers will not inherit their parent's options.
*/
declare class CelosiaRouter<Strict extends boolean = true> {
protected _celosiaRouterOptions: CelosiaRouterConstructorOptions<Strict>;
protected _isStrict: Strict;
private _expressRouter;
protected _cachedExtensionsProxy: CelosiaJS.CelosiaRouter<Strict> | null;
protected logger: import("winston").Logger;
constructor(options: CelosiaRouterConstructorOptions<Strict>);
/**
* Returns the options used to initialize this instance.
*/
get celosiaRouterOptions(): CelosiaRouterConstructorOptions<Strict>;
/**
* User-defined extensions method.
* Register by using `ExtensionsRegistry.registerCelosiaRouterExtension`.
*/
get extensions(): CelosiaJS.CelosiaRouter<Strict>;
/**
* Returns true if this router is strict.
*/
get isStrict(): Strict;
/**
* Express router object.
*/
get expressRouter(): import("express-serve-static-core").Router;
/**
* Use another router extending the path of this router.
*/
useRouters(path: string, ...routers: [CelosiaRouter<any>, ...CelosiaRouter<any>[]]): this;
/**
* Use another router on the same path.
*/
useRouters(...routers: [CelosiaRouter<any>, ...CelosiaRouter<any>[]]): this;
/**
* For middlewares without any input or output
*/
useMiddlewares(path: string, ...middlewares: [NoInputMiddleware, ...NoInputMiddleware[]]): this;
/**
* For middlewares without any input or output
*/
useMiddlewares(...middlewares: [NoInputMiddleware, ...NoInputMiddleware[]]): this;
/**
* Group routes by a path, creating another router.
*/
group(path: string, callback: CelosiaRouterGroupCallback<Strict>): void;
/**
* Group routes by a path, creating another router.
*/
group(path: string, options: CelosiaRouterConstructorOptions<Strict>, callback: CelosiaRouterGroupCallback<Strict>): void;
/**
* Group routes, creating another router.
*/
group(callback: CelosiaRouterGroupCallback<Strict>): void;
/**
* Group routes, creating another router.
*/
group(options: CelosiaRouterConstructorOptions<Strict>, callback: CelosiaRouterGroupCallback<Strict>): void;
/**
* Register a get route to a controller with pre-validation middlewares.
*/
get<C extends Controller<any, CelosiaRequest<any, any, any, any>, any>, PreValidationMiddlewares extends Middleware<CelosiaRequest, any, any, any>[], Middlewares extends MiddlewareArray>(path: string, preValidationMiddlewares: PreValidationMiddlewares & ValidateMiddlewares<C, PreValidationMiddlewares>, middlewares: Middlewares & ValidateMiddlewares<C, Middlewares, MergeMiddlewaresOutput<PreValidationMiddlewares>>, controller: C & ValidateControllerWithoutBody<C, Middlewares, Strict>): this;
/**
* Register a get route to a controller.
*/
get<C extends Controller<any, CelosiaRequest<any, any, any, any>, any>, Middlewares extends MiddlewareArray>(path: string, middlewares: Middlewares & ValidateMiddlewares<C, Middlewares>, controller: C & ValidateControllerWithoutBody<C, Middlewares, Strict>): this;
/**
* Register a head route to a controller with pre-validation middlewares.
*/
head<C extends Controller<any, CelosiaRequest<any, any, any, any>, any>, PreValidationMiddlewares extends Middleware<CelosiaRequest, any, any, any>[], Middlewares extends MiddlewareArray>(path: string, preValidationMiddlewares: PreValidationMiddlewares & ValidateMiddlewares<C, PreValidationMiddlewares>, middlewares: Middlewares & ValidateMiddlewares<C, Middlewares, MergeMiddlewaresOutput<PreValidationMiddlewares>>, controller: C & ValidateControllerWithoutBody<C, Middlewares, Strict>): this;
/**
* Register a head route to a controller.
*/
head<C extends Controller<any, CelosiaRequest<any, any, any, any>, any>, Middlewares extends MiddlewareArray>(path: string, middlewares: Middlewares & ValidateMiddlewares<C, Middlewares>, controller: C & ValidateControllerWithoutBody<C, Middlewares, Strict>): this;
/**
* Register a post route to a controller with pre-validation middlewares.
*/
post<C extends Controller<any, CelosiaRequest<any, any, any, any>, any>, PreValidationMiddlewares extends Middleware<CelosiaRequest, any, any, any>[], Middlewares extends MiddlewareArray>(path: string, preValidationMiddlewares: PreValidationMiddlewares & ValidateMiddlewares<C, PreValidationMiddlewares>, middlewares: Middlewares & ValidateMiddlewares<C, Middlewares, MergeMiddlewaresOutput<PreValidationMiddlewares>>, controller: C & ValidateController<C, Middlewares>): this;
/**
* Register a post route to a controller.
*/
post<C extends Controller<any, CelosiaRequest<any, any, any, any>, any>, Middlewares extends MiddlewareArray>(path: string, middlewares: Middlewares & ValidateMiddlewares<C, Middlewares>, controller: C & ValidateController<C, Middlewares>): this;
/**
* Register a put route to a controller with pre-validation middlewares.
*/
put<C extends Controller<any, CelosiaRequest<any, any, any, any>, any>, PreValidationMiddlewares extends Middleware<CelosiaRequest, any, any, any>[], Middlewares extends MiddlewareArray>(path: string, preValidationMiddlewares: PreValidationMiddlewares & ValidateMiddlewares<C, PreValidationMiddlewares>, middlewares: Middlewares & ValidateMiddlewares<C, Middlewares, MergeMiddlewaresOutput<PreValidationMiddlewares>>, controller: C & ValidateController<C, Middlewares>): this;
/**
* Register a put route to a controller.
*/
put<C extends Controller<any, CelosiaRequest<any, any, any, any>, any>, Middlewares extends MiddlewareArray>(path: string, middlewares: Middlewares & ValidateMiddlewares<C, Middlewares>, controller: C & ValidateController<C, Middlewares>): this;
/**
* Register a patch route to a controller with pre-validation middlewares.
*/
patch<C extends Controller<any, CelosiaRequest<any, any, any, any>, any>, PreValidationMiddlewares extends Middleware<CelosiaRequest, any, any, any>[], Middlewares extends MiddlewareArray>(path: string, preValidationMiddlewares: PreValidationMiddlewares & ValidateMiddlewares<C, PreValidationMiddlewares>, middlewares: Middlewares & ValidateMiddlewares<C, Middlewares, MergeMiddlewaresOutput<PreValidationMiddlewares>>, controller: C & ValidateController<C, Middlewares>): this;
/**
* Register a patch route to a controller.
*/
patch<C extends Controller<any, CelosiaRequest<any, any, any, any>, any>, Middlewares extends MiddlewareArray>(path: string, middlewares: Middlewares & ValidateMiddlewares<C, Middlewares>, controller: C & ValidateController<C, Middlewares>): this;
/**
* Register a delete route to a controller with pre-validation middlewares.
*/
delete<C extends Controller<any, CelosiaRequest<any, any, any, any>, any>, PreValidationMiddlewares extends Middleware<CelosiaRequest, any, any, any>[], Middlewares extends MiddlewareArray>(path: string, preValidationMiddlewares: PreValidationMiddlewares & ValidateMiddlewares<C, PreValidationMiddlewares>, middlewares: Middlewares & ValidateMiddlewares<C, Middlewares, MergeMiddlewaresOutput<PreValidationMiddlewares>>, controller: C & ValidateControllerWithoutBody<C, Middlewares, Strict>): this;
/**
* Register a delete route to a controller.
*/
delete<C extends Controller<any, CelosiaRequest<any, any, any, any>, any>, Middlewares extends MiddlewareArray>(path: string, middlewares: Middlewares & ValidateMiddlewares<C, Middlewares>, controller: C & ValidateControllerWithoutBody<C, Middlewares, Strict>): this;
/**
* Register a options route to a controller with pre-validation middlewares.
*/
options<C extends Controller<any, CelosiaRequest<any, any, any, any>, any>, PreValidationMiddlewares extends Middleware<CelosiaRequest, any, any, any>[], Middlewares extends MiddlewareArray>(path: string, preValidationMiddlewares: PreValidationMiddlewares & ValidateMiddlewares<C, PreValidationMiddlewares>, middlewares: Middlewares & ValidateMiddlewares<C, Middlewares, MergeMiddlewaresOutput<PreValidationMiddlewares>>, controller: C & ValidateControllerWithoutBody<C, Middlewares, Strict>): this;
/**
* Register a options route to a controller.
*/
options<C extends Controller<any, CelosiaRequest<any, any, any, any>, any>, Middlewares extends MiddlewareArray>(path: string, middlewares: Middlewares & ValidateMiddlewares<C, Middlewares>, controller: C & ValidateControllerWithoutBody<C, Middlewares, Strict>): this;
/**
* Register a route which handles every methods to a controller with pre-validation middlewares.
*/
all<C extends Controller<any, CelosiaRequest<any, any, any, any>, any>, PreValidationMiddlewares extends Middleware<CelosiaRequest, any, any, any>[], Middlewares extends MiddlewareArray>(path: string, preValidationMiddlewares: PreValidationMiddlewares & ValidateMiddlewares<C, PreValidationMiddlewares>, middlewares: Middlewares & ValidateMiddlewares<C, Middlewares, MergeMiddlewaresOutput<PreValidationMiddlewares>>, controller: C & ValidateController<C, Middlewares>): this;
/**
* Register a route which handles every methods to a controller.
*/
all<C extends Controller<any, CelosiaRequest<any, any, any, any>, any>, Middlewares extends MiddlewareArray>(path: string, middlewares: Middlewares & ValidateMiddlewares<C, Middlewares>, controller: C & ValidateController<C, Middlewares>): this;
private handler;
}
export default CelosiaRouter;