Add definition for custom interceptors

This commit is contained in:
Wim Looman
2015-01-12 14:47:39 +13:00
parent dc0db579e1
commit e4d5176b09
2 changed files with 84 additions and 14 deletions
+33
View File
@@ -59,9 +59,42 @@ declare module "rest" {
skip(): Client;
wrap(interceptor: Interceptor, config?: any): Client;
}
export interface Meta {
client: Client;
arguments: any;
}
}
}
declare module "rest/interceptor" {
import when = require("when");
import rest = require("rest");
// TODO: These two configs should be merged to use union output types.
interface Config {
init?: (config: any) => any;
request?: (request: rest.Request, config: any, meta: rest.Meta) => rest.Request;
response?: (response: rest.Response, config: any, meta: rest.Meta) => rest.Response;
success?: (response: rest.Response, config: any, meta: rest.Meta) => rest.Response;
error?: (response: rest.Response, config: any, meta: rest.Meta) => rest.Response;
}
interface PromiseConfig {
init?: (config: any) => any;
request?: (request: rest.Request, config: any, meta: rest.Meta) => when.Promise<rest.Request>;
response?: (response: rest.Response, config: any, meta: rest.Meta) => when.Promise<rest.Response>;
success?: (response: rest.Response, config: any, meta: rest.Meta) => when.Promise<rest.Response>;
error?: (response: rest.Response, config: any, meta: rest.Meta) => when.Promise<rest.Response>;
}
function interceptor(config: Config): rest.Interceptor;
function interceptor(config: PromiseConfig): rest.Interceptor;
export = interceptor;
}
declare module "rest/interceptor/defaultRequest" {
import rest = require("rest");