From b7e9564fdd78981f5acf927cfef4cec9a0a21d68 Mon Sep 17 00:00:00 2001 From: James O'Cull Date: Wed, 6 Jan 2016 13:34:10 -0500 Subject: [PATCH] Add router /routes support to Restify --- restify/restify.d.ts | 60 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/restify/restify.d.ts b/restify/restify.d.ts index 6fb2e6718..1cb61fd23 100644 --- a/restify/restify.d.ts +++ b/restify/restify.d.ts @@ -72,6 +72,61 @@ declare module "restify" { headers: Object; id: string; } + + interface Route { + name: string; + method: string; + path: RoutePathRegex; + spec: Object; + types: string[]; + versions: string[]; + } + + interface RouteOptions { + name: string; + method: string; + path?: string | RegExp; + url?: string | RegExp; + urlParamPattern?: RegExp; + contentType?: string | string[]; + versions?: string | string[]; + } + + interface RoutePathRegex extends RegExp { + restifyParams: string[]; + } + + interface Router { + name: string; + mounts: { [routeName: string]: Route }; + versions: string[]; + contentType: string[]; + routes: { + DELETE: Route[]; + GET: Route[]; + HEAD: Route[]; + OPTIONS: Route[]; + PATCH: Route[]; + POST: Route[]; + PUT: Route[]; + }; + log?: any; + toString: () => string; + + /** + * adds a route. + * @param {Object} options an options object + * @returns {String} returns the route name if creation is successful. + */ + mount: (options: Object) => string; + + /** + * unmounts a route. + * @param {String} name the route name + * @returns {String} the name of the deleted route (or false if it was not matched) + */ + unmount: (name: string) => string | boolean; + } interface Server extends http.Server { use(handler: RequestHandler, ...handlers: RequestHandler[]): any; @@ -124,7 +179,9 @@ declare module "restify" { close(... args: any[]): any; pre(routeCallBack: RequestHandler): any; server: http.Server; - + router: Router; + routes: Route[]; + toString: () => string; } interface ServerOptions { @@ -138,6 +195,7 @@ declare module "restify" { responseTimeHeader ?: string; responseTimeFormatter ?: (durationInMilliseconds: number) => any; handleUpgrades ?: boolean; + router ?: Router; } interface ClientOptions {