diff --git a/package.json b/package.json index 7a794fa..fd6537f 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.1.7", "description": "A wrapper for node-fetch that makes it appear like superagent.", "main": "index.js", + "typings": "typings/index.d.ts", "scripts": { "test": "npm run lint", "lint": "eslint . --ext .js --ext .json" diff --git a/typings/index.d.ts b/typings/index.d.ts new file mode 100644 index 0000000..c1a9276 --- /dev/null +++ b/typings/index.d.ts @@ -0,0 +1,84 @@ +import { Agent } from 'http'; + +type KVObject = { [name: string]: string }; + +type RequestBody = null | string | Buffer | Blob | NodeJS.ReadableStream; +interface RequestOptions { + url: string; + method?: string; + query?: KVObject; + headers?: KVObject; + body?: RequestBody; + redirects?: number; + agent?: Agent; +} + +type ResponseBody = object | string | Buffer; +interface Response { + status: number; + statusText: string; + headers: KVObject; + url: string; + ok: boolean; + raw: Buffer; + text: string; + body: ResponseBody; +} + +type StaticRequest = (url: string, options?: RequestOptions) => Request; + +declare class Request extends Promise { + public static acl: StaticRequest; + public static bind: StaticRequest; + public static checkout: StaticRequest; + public static connect: StaticRequest; + public static copy: StaticRequest; + public static delete: StaticRequest; + public static get: StaticRequest; + public static head: StaticRequest; + public static link: StaticRequest; + public static lock: StaticRequest; + // public static 'm-search': StaticRequest; + public static merge: StaticRequest; + public static mkactivity: StaticRequest; + public static mkcalendar: StaticRequest; + public static mkcol: StaticRequest; + public static move: StaticRequest; + public static notify: StaticRequest; + public static options: StaticRequest; + public static patch: StaticRequest; + public static post: StaticRequest; + public static propfind: StaticRequest; + public static proppatch: StaticRequest; + public static purge: StaticRequest; + public static put: StaticRequest; + public static rebind: StaticRequest; + public static report: StaticRequest; + public static search: StaticRequest; + public static source: StaticRequest; + public static subscribe: StaticRequest; + public static trace: StaticRequest; + public static unbind: StaticRequest; + public static unlink: StaticRequest; + public static unlock: StaticRequest; + public static unsubscribe: StaticRequest; + + constructor(options: RequestOptions); + public end(cb?: (err: Error, response?: ResponseBody) => void): Promise; + + public query(params: KVObject): this; + public query(name: string, value: string): this; + + public set(headers: KVObject): this; + public set(name: string, value: string): this; + + public attach(data: KVObject): this; + public attach(name: string, value: string): this; + + public send(body: RequestBody, raw?: boolean): this; + public redirects(amount: number): this; + + protected _request(): Promise; +} + +export = Request;