Skip to content

Commit

Permalink
Merge pull request #74 from Wintereise/master
Browse files Browse the repository at this point in the history
Update TypeScript definition file to be compatible with 0.9.x
  • Loading branch information
jeremydaly committed Nov 21, 2018
2 parents 8d9757d + a9330d4 commit 8ac70be
Showing 1 changed file with 56 additions and 30 deletions.
86 changes: 56 additions & 30 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
APIGatewayEvent,
APIGatewayEventRequestContext,
Context,
Context
} from 'aws-lambda';

declare interface CookieOptions {
export declare interface CookieOptions {
domain?: string;
expires?: Date;
httpOnly?: boolean;
Expand All @@ -14,7 +14,7 @@ declare interface CookieOptions {
sameSite?: boolean | 'Strict' | 'Lax';
}

declare interface CorsOptions {
export declare interface CorsOptions {
credentials?: boolean;
exposeHeaders?: string;
headers?: string;
Expand All @@ -23,7 +23,7 @@ declare interface CorsOptions {
origin?: string;
}

declare interface FileOptions {
export declare interface FileOptions {
maxAge?: number;
root?: string;
lastModified?: boolean | string;
Expand All @@ -32,35 +32,37 @@ declare interface FileOptions {
private?: boolean;
}

declare interface App {
export declare interface App {
[namespace: string]: HandlerFunction;
}
declare type ErrorCallback = (error?: Error) => void;
declare type HandlerFunction = (req: Request, res: Response) => void | {} | Promise<{}>;
declare type LoggerFunction = (message: string) => void;
declare type NextFunction = () => void;
declare type TimestampFunction = () => string;
declare type SerializerFunction = (body: object) => string;
declare type FinallyFunction = (req: Request, res: Response) => void;

declare type METHODS = 'GET'
| 'POST'
| 'PUT'
| 'PATCH'
| 'DELETE'
| 'OPTIONS'
| 'HEAD'
| 'ANY';

declare interface SamplingOptions {

export declare type Middleware = (req: Request, res: Response, next: Middleware) => void;
export declare type ErrorHandlingMiddleware = (error: Error, req: Request, res: Response, next: ErrorHandlingMiddleware) => void;
export declare type ErrorCallback = (error?: Error) => void;
export declare type HandlerFunction = (req: Request, res: Response) => void | {} | Promise<{}>;
export declare type LoggerFunction = (message: string) => void;
export declare type NextFunction = () => void;
export declare type TimestampFunction = () => string;
export declare type SerializerFunction = (body: object) => string;
export declare type FinallyFunction = (req: Request, res: Response) => void;
export declare type METHODS = 'GET'
| 'POST'
| 'PUT'
| 'PATCH'
| 'DELETE'
| 'OPTIONS'
| 'HEAD'
| 'ANY';

export declare interface SamplingOptions {
route?: string;
target?: number;
rate?: number
period?: number;
method?: string | string[];
}

declare interface LoggerOptions {
export declare interface LoggerOptions {
access?: boolean | string;
customKey?: string;
detail?: boolean;
Expand All @@ -83,7 +85,7 @@ declare interface LoggerOptions {
stack?: boolean;
}

declare interface Options {
export declare interface Options {
base?: string;
callbackName?: string;
logger?: boolean | LoggerOptions;
Expand All @@ -94,7 +96,7 @@ declare interface Options {
version?: string;
}

declare class Request {
export declare class Request {
app: API;
version: string;
id: string;
Expand Down Expand Up @@ -141,7 +143,7 @@ declare class Request {
};
}

declare class Response {
export declare class Response {
status(code: number): this;
header(key: string, value: string): this;
getHeader(key: string): string;
Expand Down Expand Up @@ -169,7 +171,7 @@ declare class Response {
sendFile(file: string | Buffer, options?: FileOptions, callback?: ErrorCallback);
}

declare class API {
export declare class API {
app(namespace: string, handler: HandlerFunction): App;
app(options: App): App;

Expand All @@ -183,10 +185,34 @@ declare class API {
any(path: string, handler: HandlerFunction): void;
METHOD(method: METHODS, path: string, handler: HandlerFunction): void;

use(req: Request, res: Response, next: NextFunction): void;

use(paths: string[], middleware: Middleware);
use (middleware: Middleware);
use (errorHandlingMiddleware: ErrorHandlingMiddleware);

finally(callback: FinallyFunction): void;

run(event: APIGatewayEvent, context: APIGatewayEventRequestContext): {};
run(event: APIGatewayEvent, context: Context): {};
}

export declare class RouteError extends Error {
constructor(message: string, path: string);
}

export declare class MethodError extends Error {
constructor(message: string, method: METHODS, path: string);
}

export declare class ConfigurationError extends Error {
constructor(message: string);
}

export declare class ResponseError extends Error {
constructor(message: string, code: number);
}

export declare class FileError extends Error {
constructor(message: string, err: object);
}

declare function createAPI(options?: Options): API;
Expand Down

0 comments on commit 8ac70be

Please sign in to comment.