microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/typings/request/request.d.ts
252lines · modecode
| 1 | // Type definitions for request |
| 2 | // Project: https://github.com/mikeal/request |
| 3 | // Definitions by: Carlos Ballesteros Velasco <https://github.com/soywiz>, bonnici <https://github.com/bonnici>, Bart van der Schoor <https://github.com/Bartvds>, Joe Skeen <http://github.com/joeskeen> |
| 4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped |
| 5 | |
| 6 | // Imported from: https://github.com/soywiz/typescript-node-definitions/d.ts |
| 7 | |
| 8 | /// <reference path="../node/node.d.ts" /> |
| 9 | /// <reference path="../form-data/form-data.d.ts" /> |
| 10 | |
| 11 | declare module 'request' { |
| 12 | import stream = require('stream'); |
| 13 | import http = require('http'); |
| 14 | import FormData = require('form-data'); |
| 15 | import url = require('url'); |
| 16 | import fs = require('fs'); |
| 17 | |
| 18 | namespace request { |
| 19 | export interface RequestAPI<TRequest extends Request, |
| 20 | TOptions extends CoreOptions, |
| 21 | TUriUrlOptions> { |
| 22 | |
| 23 | defaults(options: TOptions): RequestAPI<TRequest, TOptions, RequiredUriUrl>; |
| 24 | defaults(options: RequiredUriUrl & TOptions): DefaultUriUrlRequestApi<TRequest, TOptions, OptionalUriUrl>; |
| 25 | |
| 26 | (uri: string, options?: TOptions, callback?: RequestCallback): TRequest; |
| 27 | (uri: string, callback?: RequestCallback): TRequest; |
| 28 | (options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest; |
| 29 | |
| 30 | get(uri: string, options?: TOptions, callback?: RequestCallback): TRequest; |
| 31 | get(uri: string, callback?: RequestCallback): TRequest; |
| 32 | get(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest; |
| 33 | |
| 34 | post(uri: string, options?: TOptions, callback?: RequestCallback): TRequest; |
| 35 | post(uri: string, callback?: RequestCallback): TRequest; |
| 36 | post(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest; |
| 37 | |
| 38 | put(uri: string, options?: TOptions, callback?: RequestCallback): TRequest; |
| 39 | put(uri: string, callback?: RequestCallback): TRequest; |
| 40 | put(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest; |
| 41 | |
| 42 | head(uri: string, options?: TOptions, callback?: RequestCallback): TRequest; |
| 43 | head(uri: string, callback?: RequestCallback): TRequest; |
| 44 | head(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest; |
| 45 | |
| 46 | patch(uri: string, options?: TOptions, callback?: RequestCallback): TRequest; |
| 47 | patch(uri: string, callback?: RequestCallback): TRequest; |
| 48 | patch(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest; |
| 49 | |
| 50 | del(uri: string, options?: TOptions, callback?: RequestCallback): TRequest; |
| 51 | del(uri: string, callback?: RequestCallback): TRequest; |
| 52 | del(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest; |
| 53 | |
| 54 | forever(agentOptions: any, optionsArg: any): TRequest; |
| 55 | jar(): CookieJar; |
| 56 | cookie(str: string): Cookie; |
| 57 | |
| 58 | initParams: any; |
| 59 | debug: boolean; |
| 60 | } |
| 61 | |
| 62 | interface DefaultUriUrlRequestApi<TRequest extends Request, |
| 63 | TOptions extends CoreOptions, |
| 64 | TUriUrlOptions> extends RequestAPI<TRequest, TOptions, TUriUrlOptions> { |
| 65 | |
| 66 | defaults(options: TOptions): DefaultUriUrlRequestApi<TRequest, TOptions, OptionalUriUrl>; |
| 67 | (): TRequest; |
| 68 | get(): TRequest; |
| 69 | post(): TRequest; |
| 70 | put(): TRequest; |
| 71 | head(): TRequest; |
| 72 | patch(): TRequest; |
| 73 | del(): TRequest; |
| 74 | } |
| 75 | |
| 76 | interface CoreOptions { |
| 77 | baseUrl?: string; |
| 78 | callback?: (error: any, response: http.IncomingMessage, body: any) => void; |
| 79 | jar?: any; // CookieJar |
| 80 | formData?: any; // Object |
| 81 | form?: any; // Object or string |
| 82 | auth?: AuthOptions; |
| 83 | oauth?: OAuthOptions; |
| 84 | aws?: AWSOptions; |
| 85 | hawk?: HawkOptions; |
| 86 | qs?: any; |
| 87 | json?: any; |
| 88 | multipart?: RequestPart[] | Multipart; |
| 89 | agentOptions?: any; |
| 90 | agentClass?: any; |
| 91 | forever?: any; |
| 92 | host?: string; |
| 93 | port?: number; |
| 94 | method?: string; |
| 95 | headers?: Headers; |
| 96 | body?: any; |
| 97 | followRedirect?: boolean | ((response: http.IncomingMessage) => boolean); |
| 98 | followAllRedirects?: boolean; |
| 99 | maxRedirects?: number; |
| 100 | encoding?: string; |
| 101 | pool?: any; |
| 102 | timeout?: number; |
| 103 | proxy?: any; |
| 104 | strictSSL?: boolean; |
| 105 | gzip?: boolean; |
| 106 | preambleCRLF?: boolean; |
| 107 | postambleCRLF?: boolean; |
| 108 | key?: Buffer; |
| 109 | cert?: Buffer; |
| 110 | passphrase?: string; |
| 111 | ca?: Buffer; |
| 112 | har?: HttpArchiveRequest; |
| 113 | useQuerystring?: boolean; |
| 114 | } |
| 115 | |
| 116 | interface UriOptions { |
| 117 | uri: string; |
| 118 | } |
| 119 | interface UrlOptions { |
| 120 | url: string; |
| 121 | } |
| 122 | export type RequiredUriUrl = UriOptions | UrlOptions; |
| 123 | |
| 124 | interface OptionalUriUrl { |
| 125 | uri?: string; |
| 126 | url?: string; |
| 127 | } |
| 128 | export type Options = RequiredUriUrl & CoreOptions; |
| 129 | |
| 130 | export interface RequestCallback { |
| 131 | (error: any, response: http.IncomingMessage, body: any): void; |
| 132 | } |
| 133 | |
| 134 | export interface HttpArchiveRequest { |
| 135 | url?: string; |
| 136 | method?: string; |
| 137 | headers?: NameValuePair[]; |
| 138 | postData?: { |
| 139 | mimeType?: string; |
| 140 | params?: NameValuePair[]; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | export interface NameValuePair { |
| 145 | name: string; |
| 146 | value: string; |
| 147 | } |
| 148 | |
| 149 | export interface Multipart { |
| 150 | chunked?: boolean; |
| 151 | data?: { |
| 152 | 'content-type'?: string, |
| 153 | body: string |
| 154 | }[]; |
| 155 | } |
| 156 | |
| 157 | export interface RequestPart { |
| 158 | headers?: Headers; |
| 159 | body: any; |
| 160 | } |
| 161 | |
| 162 | export interface Request extends stream.Stream { |
| 163 | readable: boolean; |
| 164 | writable: boolean; |
| 165 | |
| 166 | getAgent(): http.Agent; |
| 167 | //start(): void; |
| 168 | //abort(): void; |
| 169 | pipeDest(dest: any): void; |
| 170 | setHeader(name: string, value: string, clobber?: boolean): Request; |
| 171 | setHeaders(headers: Headers): Request; |
| 172 | qs(q: Object, clobber?: boolean): Request; |
| 173 | form(): FormData.FormData; |
| 174 | form(form: any): Request; |
| 175 | multipart(multipart: RequestPart[]): Request; |
| 176 | json(val: any): Request; |
| 177 | aws(opts: AWSOptions, now?: boolean): Request; |
| 178 | auth(username: string, password: string, sendInmediately?: boolean, bearer?: string): Request; |
| 179 | oauth(oauth: OAuthOptions): Request; |
| 180 | jar(jar: CookieJar): Request; |
| 181 | |
| 182 | on(event: string, listener: Function): Request; |
| 183 | |
| 184 | write(buffer: Buffer, cb?: Function): boolean; |
| 185 | write(str: string, cb?: Function): boolean; |
| 186 | write(str: string, encoding: string, cb?: Function): boolean; |
| 187 | write(str: string, encoding?: string, fd?: string): boolean; |
| 188 | end(): void; |
| 189 | end(chunk: Buffer, cb?: Function): void; |
| 190 | end(chunk: string, cb?: Function): void; |
| 191 | end(chunk: string, encoding: string, cb?: Function): void; |
| 192 | pause(): void; |
| 193 | resume(): void; |
| 194 | abort(): void; |
| 195 | destroy(): void; |
| 196 | toJSON(): Object; |
| 197 | } |
| 198 | |
| 199 | export interface Headers { |
| 200 | [key: string]: any; |
| 201 | } |
| 202 | |
| 203 | export interface AuthOptions { |
| 204 | user?: string; |
| 205 | username?: string; |
| 206 | pass?: string; |
| 207 | password?: string; |
| 208 | sendImmediately?: boolean; |
| 209 | bearer?: string; |
| 210 | } |
| 211 | |
| 212 | export interface OAuthOptions { |
| 213 | callback?: string; |
| 214 | consumer_key?: string; |
| 215 | consumer_secret?: string; |
| 216 | token?: string; |
| 217 | token_secret?: string; |
| 218 | verifier?: string; |
| 219 | } |
| 220 | |
| 221 | export interface HawkOptions { |
| 222 | credentials: any; |
| 223 | } |
| 224 | |
| 225 | export interface AWSOptions { |
| 226 | secret: string; |
| 227 | bucket?: string; |
| 228 | } |
| 229 | |
| 230 | export interface CookieJar { |
| 231 | setCookie(cookie: Cookie, uri: string | url.Url, options?: any): void |
| 232 | getCookieString(uri: string | url.Url): string |
| 233 | getCookies(uri: string | url.Url): Cookie[] |
| 234 | } |
| 235 | |
| 236 | export interface CookieValue { |
| 237 | name: string; |
| 238 | value: any; |
| 239 | httpOnly: boolean; |
| 240 | } |
| 241 | |
| 242 | export interface Cookie extends Array<CookieValue> { |
| 243 | constructor(name: string, req: Request): void; |
| 244 | str: string; |
| 245 | expires: Date; |
| 246 | path: string; |
| 247 | toString(): string; |
| 248 | } |
| 249 | } |
| 250 | var request: request.RequestAPI<request.Request, request.CoreOptions, request.RequiredUriUrl>; |
| 251 | export = request; |
| 252 | } |
| 253 | |