diff --git a/types/urllib/index.d.ts b/types/urllib/index.d.ts index 25a583579b..44a4e9d77e 100644 --- a/types/urllib/index.d.ts +++ b/types/urllib/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for urllib 2.25.4 +// Type definitions for urllib 2.25 // Project: http://github.com/node-modules/urllib // Definitions by: SoraYama // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -10,254 +10,251 @@ import * as url from 'url'; import { Readable, Writable } from 'stream'; import { EventEmitter } from 'events'; -declare module 'urllib' { - - export interface IRequestOptions { - /** Request method, defaults to GET. Could be GET, POST, DELETE or PUT. Alias 'type'. */ - method?: "GET" | "POST" | "DELETE" | "PUT"; - /** Data to be sent. Will be stringify automatically. */ - data?: object; - /** Force convert data to query string. */ - dataAsQueryString?: boolean; - /** Manually set the content of payload. If set, data will be ignored. */ - content?: string | Buffer; - /** Stream to be pipe to the remote.If set, data and content will be ignored. */ - stream?: Readable; - /** - * A writable stream to be piped by the response stream. - * Responding data will be write to this stream and callback - * will be called with data set null after finished writing. - */ - writeStream?: Writable; - /** consume the writeStream, invoke the callback after writeStream close. */ - consumeWriteStream?: boolean; - /** Type of request data.Could be json.If it's json, will auto set Content-Type: application/json header. */ - contentType?: string; - /** - * urllib default use querystring to stringify form data which don't support nested object, - * will use qs instead of querystring to support nested object by set this option to true. - */ - nestedQuerystring?: boolean; - /** - * Type of response data. Could be text or json. - * If it's text, the callbacked data would be a String. - * If it's json, the data of callback would be a parsed JSON Object - * and will auto set Accept: application/json header. Default callbacked data would be a Buffer. - */ - dataType?: string; - /** Fix the control characters (U+0000 through U+001F) before JSON parse response. Default is false. */ - fixJSONCtlChars?: boolean; - /** Request headers. */ - headers?: object; - /** - * Request timeout in milliseconds for connecting phase and response receiving phase. - * Defaults to exports. - * TIMEOUT, both are 5s.You can use timeout: 5000 to tell urllib use same timeout on two phase or set them seperately such as - * timeout: [3000, 5000], which will set connecting timeout to 3s and response 5s. - */ - timeout?: number | number[]; - /** username:password used in HTTP Basic Authorization. */ - auth?: string; - /** username:password used in HTTP Digest Authorization. */ - digestAuth?: string; - /** HTTP Agent object.Set false if you does not use agent. */ - agent?: http.Agent; - /** HTTPS Agent object. Set false if you does not use agent. */ - httpsAgent?: https.Agent; - /** - * An array of strings or Buffers of trusted certificates. - * If this is omitted several well known "root" CAs will be used, like VeriSign. - * These are used to authorize connections. - * Notes: This is necessary only if the server uses the self - signed certificate - */ - ca?: string | Buffer | string[] | Buffer[]; - /** - * If true, the server certificate is verified against the list of supplied CAs. - * An 'error' event is emitted if verification fails.Default: true. - */ - rejectUnauthorized?: boolean; - /** A string or Buffer containing the private key, certificate and CA certs of the server in PFX or PKCS12 format. */ - pfx?: string | Buffer; - /** - * A string or Buffer containing the private key of the client in PEM format. - * Notes: This is necessary only if using the client certificate authentication - */ - key?: string | Buffer; - /** - * A string or Buffer containing the certificate key of the client in PEM format. - * Notes: This is necessary only if using the client certificate authentication - */ - cert?: string | Buffer; - /** A string of passphrase for the private key or pfx. */ - passphrase?: string; - /** A string describing the ciphers to use or exclude. */ - ciphers?: string; - /** The SSL method to use, e.g.SSLv3_method to force SSL version 3. */ - secureProtocol?: string; - /** follow HTTP 3xx responses as redirects. defaults to false. */ - followRedirect?: boolean; - /** The maximum number of redirects to follow, defaults to 10. */ - maxRedirects?: number - /** Format the redirect url by your self. Default is url.resolve(from, to). */ - formatRedirectUrl?: Function; - /** Before request hook, you can change every thing here. */ - beforeRequest?: Function; - /** let you get the res object when request connected, default false. alias customResponse */ - streaming?: boolean; - /** Accept gzip response content and auto decode it, default is false. */ - gzip?: boolean; - /** Enable timing or not, default is false. */ - timing?: boolean; - /** Enable proxy request, default is false. */ - enableProxy?: boolean; - /** proxy agent uri or options, default is null. */ - proxy?: string | object; - } - +export interface RequestOptions { + /** Request method, defaults to GET. Could be GET, POST, DELETE or PUT. Alias 'type'. */ + method?: "GET" | "POST" | "DELETE" | "PUT"; + /** Data to be sent. Will be stringify automatically. */ + data?: any; + /** Force convert data to query string. */ + dataAsQueryString?: boolean; + /** Manually set the content of payload. If set, data will be ignored. */ + content?: string | Buffer; + /** Stream to be pipe to the remote.If set, data and content will be ignored. */ + stream?: Readable; /** - * @param err Error - * @param data Outgoing message - * @param res http response + * A writable stream to be piped by the response stream. + * Responding data will be write to this stream and callback + * will be called with data set null after finished writing. */ - type Callback = (err: Error, data: any, res: http.IncomingMessage) => void; - + writeStream?: Writable; + /** consume the writeStream, invoke the callback after writeStream close. */ + consumeWriteStream?: boolean; + /** Type of request data.Could be json.If it's json, will auto set Content-Type: application/json header. */ + contentType?: string; /** - * Handle all http request, both http and https support well. - * - * @example - * // GET http://httptest.cnodejs.net - * urllib.request('http://httptest.cnodejs.net/test/get', function(err, data, res) {}); - * // POST http://httptest.cnodejs.net - * var args = { type: 'post', data: { foo: 'bar' } }; - * urllib.request('http://httptest.cnodejs.net/test/post', args, function(err, data, res) {}); - * - * @param url The URL to request, either a String or a Object that return by url.parse. - * @param options Optional, @see IRequestOptions. + * urllib default use querystring to stringify form data which don't support nested object, + * will use qs instead of querystring to support nested object by set this option to true. */ - export function request(url: string | url.URL, options?: IRequestOptions): Promise; + nestedQuerystring?: boolean; /** - * @param url The URL to request, either a String or a Object that return by url.parse. - * @param callback @see Callback + * Type of response data. Could be text or json. + * If it's text, the callbacked data would be a String. + * If it's json, the data of callback would be a parsed JSON Object + * and will auto set Accept: application/json header. Default callbacked data would be a Buffer. */ - export function request(url: string | url.URL, callback: Callback): void; + dataType?: string; + /** Fix the control characters (U+0000 through U+001F) before JSON parse response. Default is false. */ + fixJSONCtlChars?: boolean; + /** Request headers. */ + headers?: object; /** - * @param url The URL to request, either a String or a Object that return by url.parse. - * @param options Optional, @see IRequestOptions. - * @param callback @see Callback + * Request timeout in milliseconds for connecting phase and response receiving phase. + * Defaults to exports. + * TIMEOUT, both are 5s.You can use timeout: 5000 to tell urllib use same timeout on two phase or set them seperately such as + * timeout: [3000, 5000], which will set connecting timeout to 3s and response 5s. */ - export function request(url: string | url.URL, options: IRequestOptions, callback: Callback): void; - + timeout?: number | number[]; + /** username:password used in HTTP Basic Authorization. */ + auth?: string; + /** username:password used in HTTP Digest Authorization. */ + digestAuth?: string; + /** HTTP Agent object.Set false if you does not use agent. */ + agent?: http.Agent; + /** HTTPS Agent object. Set false if you does not use agent. */ + httpsAgent?: https.Agent; /** - * Handle request with a callback. - * @param url The URL to request, either a String or a Object that return by url.parse. - * @param callback @see Callback + * An array of strings or Buffers of trusted certificates. + * If this is omitted several well known "root" CAs will be used, like VeriSign. + * These are used to authorize connections. + * Notes: This is necessary only if the server uses the self - signed certificate */ - export function requestWithCallback(url: string | url.URL, callback: Callback): void; + ca?: string | Buffer | string[] | Buffer[]; /** - * @param url The URL to request, either a String or a Object that return by url.parse. - * @param options Optional, @see IRequestOptions. - * @param callback @see Callback - */ - export function requestWithCallback(url: string | url.URL, options: IRequestOptions, callback: Callback): void; - - /** - * yield urllib.requestThunk(url, args) - * @param url The URL to request, either a String or a Object that return by url.parse. - * @param options Optional, @see IRequestOptions. + * If true, the server certificate is verified against the list of supplied CAs. + * An 'error' event is emitted if verification fails.Default: true. */ - export function requestThunk(url: string | url.URL, options: IRequestOptions): (callback: Function) => void; - + rejectUnauthorized?: boolean; + /** A string or Buffer containing the private key, certificate and CA certs of the server in PFX or PKCS12 format. */ + pfx?: string | Buffer; /** - * alias to request. - * Handle all http request, both http and https support well. - * - * @example - * // GET http://httptest.cnodejs.net - * urllib.request('http://httptest.cnodejs.net/test/get', function(err, data, res) {}); - * // POST http://httptest.cnodejs.net - * var args = { type: 'post', data: { foo: 'bar' } }; - * urllib.request('http://httptest.cnodejs.net/test/post', args, function(err, data, res) {}); - * - * @param url The URL to request, either a String or a Object that return by url.parse. - * @param options Optional, @see IRequestOptions. + * A string or Buffer containing the private key of the client in PEM format. + * Notes: This is necessary only if using the client certificate authentication */ - export function curl(url: string | url.URL, options?: IRequestOptions): Promise; + key?: string | Buffer; /** - * @param url The URL to request, either a String or a Object that return by url.parse. - * @param callback @see Callback + * A string or Buffer containing the certificate key of the client in PEM format. + * Notes: This is necessary only if using the client certificate authentication */ - export function curl(url: string | url.URL, callback: Callback): void; - /** - * @param url The URL to request, either a String or a Object that return by url.parse. - * @param options Optional, @see IRequestOptions. - * @param callback @see Callback - */ - export function curl(url: string | url.URL, options: IRequestOptions, callback: Callback): void; - - - /** - * The default request timeout(in milliseconds). - * @type {Number} - * @const - */ - export const TIMEOUT: number; - /** - * The default request & response timeout(in milliseconds). - * @type {Array} - * @const - */ - export const TIMEOUTS: [number, number]; - - /** - * Request user agent. - * @type {String} - * @const - */ - export const USER_AGENT: string; - - /** - * Request http agent. - * @type {http.Agent} - */ - export const agent: http.Agent; - - /** - * Request https agent. - * @type {https.Agent} - */ - export const httpsAgent: https.Agent; - - export class HttpClient extends EventEmitter { - constructor(options?: IRequestOptions); - - request(url: string | url.URL, callback: Callback): void; - request(url: string | url.URL, options: IRequestOptions, callback: Callback): void; - - curl(url: string | url.URL, callback: Callback): void; - curl(url: string | url.URL, options: IRequestOptions, callback: Callback): void; - - requestThunk(url: string | url.URL, options?: IRequestOptions): (callback: Function) => void; - } - - /** - * request method only return a promise, - * compatible with async/await and generator in co. - * @constructor {IRequestOptions} Optional @see IRequestOptions - */ - export class HttpClient2 extends EventEmitter { - constructor(options?: IRequestOptions); - - request(url: string | url.URL, options?: IRequestOptions): Promise; - - curl(url: string | url.URL, options?: IRequestOptions): Promise; - - requestThunk(url: string | url.URL, options?: IRequestOptions): (callback: Function) => void; - } - - /** - * Create a HttpClient incetance. - * @param options - * @return {HttpClient} HttpClient incetance. - */ - export function create(options?: IRequestOptions): HttpClient; + cert?: string | Buffer; + /** A string of passphrase for the private key or pfx. */ + passphrase?: string; + /** A string describing the ciphers to use or exclude. */ + ciphers?: string; + /** The SSL method to use, e.g.SSLv3_method to force SSL version 3. */ + secureProtocol?: string; + /** follow HTTP 3xx responses as redirects. defaults to false. */ + followRedirect?: boolean; + /** The maximum number of redirects to follow, defaults to 10. */ + maxRedirects?: number; + /** Format the redirect url by your self. Default is url.resolve(from, to). */ + formatRedirectUrl?: (a: any, b: any) => void; + /** Before request hook, you can change every thing here. */ + beforeRequest?: (...args: any[]) => void; + /** let you get the res object when request connected, default false. alias customResponse */ + streaming?: boolean; + /** Accept gzip response content and auto decode it, default is false. */ + gzip?: boolean; + /** Enable timing or not, default is false. */ + timing?: boolean; + /** Enable proxy request, default is false. */ + enableProxy?: boolean; + /** proxy agent uri or options, default is null. */ + proxy?: string | object; } + +/** + * @param err Error + * @param data Outgoing message + * @param res http response + */ +type Callback = (err: Error, data: any, res: http.IncomingMessage) => void; + +/** + * Handle all http request, both http and https support well. + * + * @example + * // GET http://httptest.cnodejs.net + * urllib.request('http://httptest.cnodejs.net/test/get', function(err, data, res) {}); + * // POST http://httptest.cnodejs.net + * var args = { type: 'post', data: { foo: 'bar' } }; + * urllib.request('http://httptest.cnodejs.net/test/post', args, function(err, data, res) {}); + * + * @param url The URL to request, either a String or a Object that return by url.parse. + * @param options Optional, @see RequestOptions. + */ +export function request(url: string | url.URL, options?: RequestOptions): Promise; +/** + * @param url The URL to request, either a String or a Object that return by url.parse. + * @param callback @see Callback + */ +export function request(url: string | url.URL, callback: Callback): void; +/** + * @param url The URL to request, either a String or a Object that return by url.parse. + * @param options Optional, @see RequestOptions. + * @param callback @see Callback + */ +export function request(url: string | url.URL, options: RequestOptions, callback: Callback): void; + +/** + * Handle request with a callback. + * @param url The URL to request, either a String or a Object that return by url.parse. + * @param callback @see Callback + */ +export function requestWithCallback(url: string | url.URL, callback: Callback): void; +/** + * @param url The URL to request, either a String or a Object that return by url.parse. + * @param options Optional, @see RequestOptions. + * @param callback @see Callback + */ +export function requestWithCallback(url: string | url.URL, options: RequestOptions, callback: Callback): void; + +/** + * yield urllib.requestThunk(url, args) + * @param url The URL to request, either a String or a Object that return by url.parse. + * @param options Optional, @see RequestOptions. + */ +export function requestThunk(url: string | url.URL, options: RequestOptions): (callback: (...args: any[]) => void) => void; + +/** + * alias to request. + * Handle all http request, both http and https support well. + * + * @example + * // GET http://httptest.cnodejs.net + * urllib.request('http://httptest.cnodejs.net/test/get', function(err, data, res) {}); + * // POST http://httptest.cnodejs.net + * var args = { type: 'post', data: { foo: 'bar' } }; + * urllib.request('http://httptest.cnodejs.net/test/post', args, function(err, data, res) {}); + * + * @param url The URL to request, either a String or a Object that return by url.parse. + * @param options Optional, @see RequestOptions. + */ +export function curl(url: string | url.URL, options?: RequestOptions): Promise; +/** + * @param url The URL to request, either a String or a Object that return by url.parse. + * @param callback @see Callback + */ +export function curl(url: string | url.URL, callback: Callback): void; +/** + * @param url The URL to request, either a String or a Object that return by url.parse. + * @param options Optional, @see RequestOptions. + * @param callback @see Callback + */ +export function curl(url: string | url.URL, options: RequestOptions, callback: Callback): void; +/** + * The default request timeout(in milliseconds). + * @type {Number} + * @const + */ +export const TIMEOUT: number; +/** + * The default request & response timeout(in milliseconds). + * @type {Array} + * @const + */ +export const TIMEOUTS: [number, number]; + +/** + * Request user agent. + * @type {String} + * @const + */ +export const USER_AGENT: string; + +/** + * Request http agent. + * @type {http.Agent} + */ +export const agent: http.Agent; + +/** + * Request https agent. + * @type {https.Agent} + */ +export const httpsAgent: https.Agent; + +export class HttpClient extends EventEmitter { + constructor(options?: RequestOptions); + + request(url: string | url.URL, callback: Callback): void; + request(url: string | url.URL, options: RequestOptions, callback: Callback): void; + + curl(url: string | url.URL, callback: Callback): void; + curl(url: string | url.URL, options: RequestOptions, callback: Callback): void; + + requestThunk(url: string | url.URL, options?: RequestOptions): (callback: (...args: any[]) => void) => void; +} + +/** + * request method only return a promise, + * compatible with async/await and generator in co. + * @constructor {RequestOptions} Optional @see RequestOptions + */ +export class HttpClient2 extends EventEmitter { + constructor(options?: RequestOptions); + + request(url: string | url.URL, options?: RequestOptions): Promise; + + curl(url: string | url.URL, options?: RequestOptions): Promise; + + requestThunk(url: string | url.URL, options?: RequestOptions): (callback: (...args: any[]) => void) => void; +} + +/** + * Create a HttpClient incetance. + * @param options + * @return {HttpClient} HttpClient incetance. + */ +export function create(options?: RequestOptions): HttpClient; + +export as namespace urllib; diff --git a/types/urllib/tslint.json b/types/urllib/tslint.json index 3db14f85ea..886f1a8b6c 100644 --- a/types/urllib/tslint.json +++ b/types/urllib/tslint.json @@ -1 +1,79 @@ -{ "extends": "dtslint/dt.json" } +{ + "extends": "dtslint/dt.json", + "rules": { + "adjacent-overload-signatures": false, + "array-type": false, + "arrow-return-shorthand": false, + "ban-types": false, + "callable-types": false, + "comment-format": false, + "dt-header": false, + "eofline": false, + "export-just-namespace": false, + "import-spacing": false, + "interface-name": false, + "interface-over-type-literal": false, + "jsdoc-format": false, + "max-line-length": false, + "member-access": false, + "new-parens": false, + "no-any-union": false, + "no-boolean-literal-compare": false, + "no-conditional-assignment": false, + "no-consecutive-blank-lines": false, + "no-construct": false, + "no-declare-current-package": false, + "no-duplicate-imports": false, + "no-duplicate-variable": false, + "no-empty-interface": false, + "no-for-in-array": false, + "no-inferrable-types": false, + "no-internal-module": false, + "no-irregular-whitespace": false, + "no-mergeable-namespace": false, + "no-misused-new": false, + "no-namespace": false, + "no-object-literal-type-assertion": false, + "no-padding": false, + "no-redundant-jsdoc": false, + "no-redundant-jsdoc-2": false, + "no-redundant-undefined": false, + "no-reference-import": false, + "no-relative-import-in-test": false, + "no-self-import": false, + "no-single-declare-module": false, + "no-string-throw": false, + "no-unnecessary-callback-wrapper": false, + "no-unnecessary-class": false, + "no-unnecessary-generics": false, + "no-unnecessary-qualifier": false, + "no-unnecessary-type-assertion": false, + "no-useless-files": false, + "no-var-keyword": false, + "no-var-requires": false, + "no-void-expression": false, + "no-trailing-whitespace": false, + "object-literal-key-quotes": false, + "object-literal-shorthand": false, + "one-line": false, + "one-variable-per-declaration": false, + "only-arrow-functions": false, + "prefer-conditional-expression": false, + "prefer-const": false, + "prefer-declare-function": false, + "prefer-for-of": false, + "prefer-method-signature": false, + "prefer-template": false, + "radix": false, + "semicolon": false, + "space-before-function-paren": false, + "space-within-parens": false, + "strict-export-declare-modifiers": false, + "trim-file": false, + "triple-equals": false, + "typedef-whitespace": false, + "unified-signatures": false, + "void-return": false, + "whitespace": false + } +} diff --git a/types/urllib/urllib-tests.ts b/types/urllib/urllib-tests.ts index 5936bcc817..cd15b42c8f 100644 --- a/types/urllib/urllib-tests.ts +++ b/types/urllib/urllib-tests.ts @@ -1,8 +1,8 @@ -import * as urllib from "."; +import * as urllib from "urllib"; urllib.curl('https://example.test.com', { method: "GET", data: { test: 'test', } -}) +});