From 1636a899188826671148fa485b8a09ffed67e90e Mon Sep 17 00:00:00 2001 From: Mateusz Stawecki Date: Wed, 11 Mar 2020 14:19:37 +0000 Subject: [PATCH 1/3] TS support api.register/routes, req.namespace #137 --- index.d.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 7e67a0e..113ebae 100644 --- a/index.d.ts +++ b/index.d.ts @@ -32,8 +32,12 @@ export declare interface FileOptions { private?: boolean; } +export declare interface RegisterOptions { + prefix?: string; +} + export declare interface App { - [namespace: string]: HandlerFunction; + [namespace: string]: any; } export declare type Middleware = (req: Request, res: Response, next: () => void) => void; @@ -138,6 +142,7 @@ export declare class Request { userAgent: string; clientType: 'desktop' | 'mobile' | 'tv' | 'tablet' | 'unknown'; clientCountry: string; + namespace: App; log: { trace: LoggerFunction; @@ -202,7 +207,10 @@ export declare class API { any(...handler: HandlerFunction[]): void; METHOD(method: METHODS, path: string, ...handler: HandlerFunction[]): void; METHOD(method: METHODS, ...handler: HandlerFunction[]): void; - + register(routes: (api: API, options?: RegisterOptions) => void, options?: RegisterOptions): void; + routes(format: true): void; + routes(format: false): string[][]; + routes(): string[][]; From 4d941263f4906364b8cd9cca02059136aa665228 Mon Sep 17 00:00:00 2001 From: Mateusz Stawecki Date: Fri, 27 Mar 2020 13:09:42 +0000 Subject: [PATCH 2/3] TS updated app() to use Package not HandlerFunction #137 --- index.d.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 113ebae..1d20862 100644 --- a/index.d.ts +++ b/index.d.ts @@ -36,8 +36,10 @@ export declare interface RegisterOptions { prefix?: string; } +export type Package = any; + export declare interface App { - [namespace: string]: any; + [namespace: string]: Package; } export declare type Middleware = (req: Request, res: Response, next: () => void) => void; @@ -186,8 +188,8 @@ export declare class Response { } export declare class API { - app(namespace: string, handler: HandlerFunction): App; - app(options: App): App; + app(namespace: string, package: Package): App; + app(packages: App): App; get(path: string, ...handler: HandlerFunction[]): void; get(...handler: HandlerFunction[]): void; From 281b1063efd7342327673a7c9564d08c11b8f221 Mon Sep 17 00:00:00 2001 From: Mateusz Stawecki Date: Sat, 18 Apr 2020 11:50:22 +0100 Subject: [PATCH 3/3] TS - fixed incorrect ErrorHandlingMiddleware callback type. --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 1d20862..cba376f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -43,7 +43,7 @@ export declare interface App { } export declare type Middleware = (req: Request, res: Response, next: () => void) => void; -export declare type ErrorHandlingMiddleware = (error: Error, req: Request, res: Response, next: ErrorHandlingMiddleware) => void; +export declare type ErrorHandlingMiddleware = (error: Error, req: Request, res: Response, next: () => void) => void; export declare type ErrorCallback = (error?: Error) => void; export declare type HandlerFunction = (req: Request, res: Response, next?: NextFunction) => void | any | Promise; export declare type LoggerFunction = (message: string) => void;