Skip to content

Commit

Permalink
Merge pull request #148 from stawecki/issue-137
Browse files Browse the repository at this point in the history
TypeScript support for api.register/routes, req.namespace (issue #137)
  • Loading branch information
jeremydaly authored Apr 27, 2020
2 parents 0f3af15 + 281b106 commit 5d4a014
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ export declare interface FileOptions {
private?: boolean;
}

export declare interface RegisterOptions {
prefix?: string;
}

export type Package = any;

export declare interface App {
[namespace: string]: HandlerFunction;
[namespace: string]: Package;
}

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<any>;
export declare type LoggerFunction = (message: string) => void;
Expand Down Expand Up @@ -138,6 +144,7 @@ export declare class Request {
userAgent: string;
clientType: 'desktop' | 'mobile' | 'tv' | 'tablet' | 'unknown';
clientCountry: string;
namespace: App;

log: {
trace: LoggerFunction;
Expand Down Expand Up @@ -181,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;
Expand All @@ -202,7 +209,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[][];



Expand Down

0 comments on commit 5d4a014

Please sign in to comment.