From 828b96fac5ce24c64cdf75125874d9ab80d9ddb8 Mon Sep 17 00:00:00 2001 From: SoraYama Date: Wed, 14 Feb 2018 00:23:07 +0800 Subject: [PATCH 01/15] create @types for urllib v2.25.4 --- types/urllib/LICENSE | 21 +++ types/urllib/README.md | 29 ++++ types/urllib/index.d.ts | 263 +++++++++++++++++++++++++++++++++++ types/urllib/tsconfig.json | 22 +++ types/urllib/tslint.json | 1 + types/urllib/urllib-tests.ts | 8 ++ 6 files changed, 344 insertions(+) create mode 100644 types/urllib/LICENSE create mode 100644 types/urllib/README.md create mode 100644 types/urllib/index.d.ts create mode 100644 types/urllib/tsconfig.json create mode 100644 types/urllib/tslint.json create mode 100644 types/urllib/urllib-tests.ts diff --git a/types/urllib/LICENSE b/types/urllib/LICENSE new file mode 100644 index 0000000000..23d4a4eb46 --- /dev/null +++ b/types/urllib/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2018 SoraYama + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/types/urllib/README.md b/types/urllib/README.md new file mode 100644 index 0000000000..36acda5c50 --- /dev/null +++ b/types/urllib/README.md @@ -0,0 +1,29 @@ +# DefinitelyTyped for Urllib + +## Current Urllib Version +`v2.25.4` +## Usage + +```bash +npm install --save-dev @types/urllib +``` + +example: +```ts +import * as urllib from "."; + +urllib.curl('https://example.test.com', { + method: "GET", + data: { + test: 'test', + } +}) +``` +## License +MIT + +## dependencies +`@types/node` + +## Author +[SoraYama](https://github.com/sorayama) diff --git a/types/urllib/index.d.ts b/types/urllib/index.d.ts new file mode 100644 index 0000000000..25a583579b --- /dev/null +++ b/types/urllib/index.d.ts @@ -0,0 +1,263 @@ +// Type definitions for urllib 2.25.4 +// Project: http://github.com/node-modules/urllib +// Definitions by: SoraYama +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import 'node'; +import * as https from 'https'; +import * as http from 'http'; +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; + } + + /** + * @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 IRequestOptions. + */ + export function request(url: string | url.URL, options?: IRequestOptions): 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 IRequestOptions. + * @param callback @see Callback + */ + export function request(url: string | url.URL, options: IRequestOptions, 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 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. + */ + export function requestThunk(url: string | url.URL, options: IRequestOptions): (callback: Function) => 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 IRequestOptions. + */ + export function curl(url: string | url.URL, options?: IRequestOptions): 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 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; +} diff --git a/types/urllib/tsconfig.json b/types/urllib/tsconfig.json new file mode 100644 index 0000000000..fe1f32cf75 --- /dev/null +++ b/types/urllib/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "urllib-tests.ts" + ] +} diff --git a/types/urllib/tslint.json b/types/urllib/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/urllib/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/urllib/urllib-tests.ts b/types/urllib/urllib-tests.ts new file mode 100644 index 0000000000..5936bcc817 --- /dev/null +++ b/types/urllib/urllib-tests.ts @@ -0,0 +1,8 @@ +import * as urllib from "."; + +urllib.curl('https://example.test.com', { + method: "GET", + data: { + test: 'test', + } +}) From d49134cc6a0c2f0c665026804df693fd0232b1f7 Mon Sep 17 00:00:00 2001 From: SoraYama Date: Wed, 14 Feb 2018 01:01:09 +0800 Subject: [PATCH 02/15] delete license file --- types/urllib/LICENSE | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 types/urllib/LICENSE diff --git a/types/urllib/LICENSE b/types/urllib/LICENSE deleted file mode 100644 index 23d4a4eb46..0000000000 --- a/types/urllib/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2018 SoraYama - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. From c4ced90519f2aa19ad7df17afd4102664aa2f0af Mon Sep 17 00:00:00 2001 From: SoraYama Date: Wed, 14 Feb 2018 01:06:35 +0800 Subject: [PATCH 03/15] enable esModuleInterop --- types/urllib/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/types/urllib/tsconfig.json b/types/urllib/tsconfig.json index fe1f32cf75..ff85f909cc 100644 --- a/types/urllib/tsconfig.json +++ b/types/urllib/tsconfig.json @@ -7,6 +7,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "esModuleInterop": true, "baseUrl": "../", "typeRoots": [ "../" From 7829555330a6513c5c902f4ead49a41d57cdbe9b Mon Sep 17 00:00:00 2001 From: SoraYama Date: Wed, 14 Feb 2018 01:18:27 +0800 Subject: [PATCH 04/15] enable strictFunctionTypes --- types/urllib/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/types/urllib/tsconfig.json b/types/urllib/tsconfig.json index ff85f909cc..2787b1459e 100644 --- a/types/urllib/tsconfig.json +++ b/types/urllib/tsconfig.json @@ -7,6 +7,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "strictFunctionTypes": true, "esModuleInterop": true, "baseUrl": "../", "typeRoots": [ From ac36a10cea0345c62341b5948b0570f1bdcc7563 Mon Sep 17 00:00:00 2001 From: SoraYama Date: Wed, 14 Feb 2018 02:31:04 +0800 Subject: [PATCH 05/15] update tslint & fix lint in index --- types/urllib/index.d.ts | 467 +++++++++++++++++------------------ types/urllib/tslint.json | 80 +++++- types/urllib/urllib-tests.ts | 4 +- 3 files changed, 313 insertions(+), 238 deletions(-) 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', } -}) +}); From dc9f306a6e9a378b3784063ecaa71b2ee2e904cb Mon Sep 17 00:00:00 2001 From: SoraYama Date: Wed, 14 Feb 2018 02:38:16 +0800 Subject: [PATCH 06/15] change object to Object for 2.1 test --- types/urllib/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/urllib/index.d.ts b/types/urllib/index.d.ts index 44a4e9d77e..d800068e84 100644 --- a/types/urllib/index.d.ts +++ b/types/urllib/index.d.ts @@ -46,7 +46,7 @@ export interface RequestOptions { /** Fix the control characters (U+0000 through U+001F) before JSON parse response. Default is false. */ fixJSONCtlChars?: boolean; /** Request headers. */ - headers?: object; + headers?: Object; /** * Request timeout in milliseconds for connecting phase and response receiving phase. * Defaults to exports. @@ -109,7 +109,7 @@ export interface RequestOptions { /** Enable proxy request, default is false. */ enableProxy?: boolean; /** proxy agent uri or options, default is null. */ - proxy?: string | object; + proxy?: string | Object; } /** From 0393e67313cc5b877777ab5d0a901cac240922c8 Mon Sep 17 00:00:00 2001 From: SoraYama Date: Wed, 14 Feb 2018 12:03:33 +0800 Subject: [PATCH 07/15] fix lint rules --- types/urllib/index.d.ts | 49 +++++++++++++------------- types/urllib/tslint.json | 74 ++-------------------------------------- 2 files changed, 26 insertions(+), 97 deletions(-) diff --git a/types/urllib/index.d.ts b/types/urllib/index.d.ts index d800068e84..e3897b77f6 100644 --- a/types/urllib/index.d.ts +++ b/types/urllib/index.d.ts @@ -10,7 +10,8 @@ import * as url from 'url'; import { Readable, Writable } from 'stream'; import { EventEmitter } from 'events'; -export interface RequestOptions { +export as namespace 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. */ @@ -130,9 +131,9 @@ type Callback = (err: Error, data: any, res: http.IncomingMessage) => void; * 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. + * @param options Optional, @see IRequestOptions. */ -export function request(url: string | url.URL, options?: RequestOptions): Promise; +export function request(url: string | url.URL, options?: IRequestOptions): Promise; /** * @param url The URL to request, either a String or a Object that return by url.parse. * @param callback @see Callback @@ -140,10 +141,10 @@ export function request(url: string | url.URL, options?: RequestOptions): Promis 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 options Optional, @see IRequestOptions. * @param callback @see Callback */ -export function request(url: string | url.URL, options: RequestOptions, callback: Callback): void; +export function request(url: string | url.URL, options: IRequestOptions, callback: Callback): void; /** * Handle request with a callback. @@ -153,17 +154,17 @@ export function request(url: string | url.URL, options: RequestOptions, 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 options Optional, @see IRequestOptions. * @param callback @see Callback */ -export function requestWithCallback(url: string | url.URL, options: RequestOptions, callback: Callback): void; +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 RequestOptions. + * @param options Optional, @see IRequestOptions. */ -export function requestThunk(url: string | url.URL, options: RequestOptions): (callback: (...args: any[]) => void) => void; +export function requestThunk(url: string | url.URL, options: IRequestOptions): (callback: (...args: any[]) => void) => void; /** * alias to request. @@ -177,9 +178,9 @@ export function requestThunk(url: string | url.URL, options: RequestOptions): (c * 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. + * @param options Optional, @see IRequestOptions. */ -export function curl(url: string | url.URL, options?: RequestOptions): Promise; +export function curl(url: string | url.URL, options?: IRequestOptions): Promise; /** * @param url The URL to request, either a String or a Object that return by url.parse. * @param callback @see Callback @@ -187,10 +188,10 @@ export function curl(url: string | url.URL, options?: RequestOptions): Promise void) => void; + requestThunk(url: string | url.URL, options?: IRequestOptions): (callback: (...args: any[]) => void) => void; } /** * request method only return a promise, * compatible with async/await and generator in co. - * @constructor {RequestOptions} Optional @see RequestOptions + * @constructor {IRequestOptions} Optional @see IRequestOptions */ export class HttpClient2 extends EventEmitter { - constructor(options?: RequestOptions); + constructor(options?: IRequestOptions); - request(url: string | url.URL, options?: RequestOptions): Promise; + request(url: string | url.URL, options?: IRequestOptions): Promise; - curl(url: string | url.URL, options?: RequestOptions): Promise; + curl(url: string | url.URL, options?: IRequestOptions): Promise; - requestThunk(url: string | url.URL, options?: RequestOptions): (callback: (...args: any[]) => void) => void; + requestThunk(url: string | url.URL, options?: IRequestOptions): (callback: (...args: any[]) => void) => void; } /** @@ -255,6 +256,4 @@ export class HttpClient2 extends EventEmitter { * @param options * @return {HttpClient} HttpClient incetance. */ -export function create(options?: RequestOptions): HttpClient; - -export as namespace urllib; +export function create(options?: IRequestOptions): HttpClient; diff --git a/types/urllib/tslint.json b/types/urllib/tslint.json index 886f1a8b6c..aa052470bd 100644 --- a/types/urllib/tslint.json +++ b/types/urllib/tslint.json @@ -1,79 +1,9 @@ { "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, + "interface-name": true, "void-return": false, - "whitespace": false + "strict-export-declare-modifiers": false } } From 4ed1e026d5122b29c7c0dd5cb53dcc6eb747b973 Mon Sep 17 00:00:00 2001 From: SoraYama Date: Wed, 14 Feb 2018 12:17:13 +0800 Subject: [PATCH 08/15] remove redundant JSDoc tags --- types/urllib/index.d.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/types/urllib/index.d.ts b/types/urllib/index.d.ts index e3897b77f6..4a4ac31214 100644 --- a/types/urllib/index.d.ts +++ b/types/urllib/index.d.ts @@ -194,33 +194,28 @@ export function curl(url: string | url.URL, callback: Callback): void; 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; @@ -239,7 +234,6 @@ export class HttpClient extends EventEmitter { /** * 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); From ba6b1b9430679dbc40ba3391236d544212d0deca Mon Sep 17 00:00:00 2001 From: SoraYama Date: Wed, 14 Feb 2018 12:24:26 +0800 Subject: [PATCH 09/15] remove type annotation in JSDoc --- types/urllib/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/urllib/index.d.ts b/types/urllib/index.d.ts index 4a4ac31214..94c77bb319 100644 --- a/types/urllib/index.d.ts +++ b/types/urllib/index.d.ts @@ -248,6 +248,6 @@ export class HttpClient2 extends EventEmitter { /** * Create a HttpClient incetance. * @param options - * @return {HttpClient} HttpClient incetance. + * @return HttpClient incetance. */ export function create(options?: IRequestOptions): HttpClient; From 32e596c7efeb35aea88da74e6fffcf80bc11319c Mon Sep 17 00:00:00 2001 From: SoraYama Date: Wed, 14 Feb 2018 13:35:42 +0800 Subject: [PATCH 10/15] fix lint rule about Object --- types/urllib/index.d.ts | 4 ++-- types/urllib/tslint.json | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/types/urllib/index.d.ts b/types/urllib/index.d.ts index 94c77bb319..ba7e701064 100644 --- a/types/urllib/index.d.ts +++ b/types/urllib/index.d.ts @@ -47,7 +47,7 @@ export interface IRequestOptions { /** Fix the control characters (U+0000 through U+001F) before JSON parse response. Default is false. */ fixJSONCtlChars?: boolean; /** Request headers. */ - headers?: Object; + headers?: { [key: string]: any }; /** * Request timeout in milliseconds for connecting phase and response receiving phase. * Defaults to exports. @@ -110,7 +110,7 @@ export interface IRequestOptions { /** Enable proxy request, default is false. */ enableProxy?: boolean; /** proxy agent uri or options, default is null. */ - proxy?: string | Object; + proxy?: string | { [key: string]: any }; } /** diff --git a/types/urllib/tslint.json b/types/urllib/tslint.json index aa052470bd..6d0aec7baa 100644 --- a/types/urllib/tslint.json +++ b/types/urllib/tslint.json @@ -1,7 +1,6 @@ { "extends": "dtslint/dt.json", "rules": { - "ban-types": false, "interface-name": true, "void-return": false, "strict-export-declare-modifiers": false From a14118e3e74183fa9cc26f84e2c8357c711e0d0a Mon Sep 17 00:00:00 2001 From: SoraYama Date: Thu, 15 Feb 2018 00:40:46 +0800 Subject: [PATCH 11/15] fix lint rules to default. --- types/urllib/index.d.ts | 2 +- types/urllib/tslint.json | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/types/urllib/index.d.ts b/types/urllib/index.d.ts index ba7e701064..4853cf3d27 100644 --- a/types/urllib/index.d.ts +++ b/types/urllib/index.d.ts @@ -118,7 +118,7 @@ export interface IRequestOptions { * @param data Outgoing message * @param res http response */ -type Callback = (err: Error, data: any, res: http.IncomingMessage) => void; +export type Callback = (err: Error, data: any, res: http.IncomingMessage) => void; /** * Handle all http request, both http and https support well. diff --git a/types/urllib/tslint.json b/types/urllib/tslint.json index 6d0aec7baa..d88586e5bd 100644 --- a/types/urllib/tslint.json +++ b/types/urllib/tslint.json @@ -1,8 +1,3 @@ { - "extends": "dtslint/dt.json", - "rules": { - "interface-name": true, - "void-return": false, - "strict-export-declare-modifiers": false - } + "extends": "dtslint/dt.json" } From 6e4afbd9204c7bd09046462ac318392e429582e1 Mon Sep 17 00:00:00 2001 From: SoraYama Date: Thu, 15 Feb 2018 00:53:01 +0800 Subject: [PATCH 12/15] remove interface prefix 'I' --- types/urllib/index.d.ts | 44 ++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/types/urllib/index.d.ts b/types/urllib/index.d.ts index 4853cf3d27..4a266cab59 100644 --- a/types/urllib/index.d.ts +++ b/types/urllib/index.d.ts @@ -11,7 +11,7 @@ import { Readable, Writable } from 'stream'; import { EventEmitter } from 'events'; export as namespace urllib; -export interface IRequestOptions { +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. */ @@ -131,9 +131,9 @@ export type Callback = (err: Error, data: any, res: http.IncomingMessage) => voi * 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. + * @param options Optional, @see RequestOptions. */ -export function request(url: string | url.URL, options?: IRequestOptions): Promise; +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 @@ -141,10 +141,10 @@ export function request(url: string | url.URL, options?: IRequestOptions): Promi 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 IRequestOptions. + * @param options Optional, @see RequestOptions. * @param callback @see Callback */ -export function request(url: string | url.URL, options: IRequestOptions, callback: Callback): void; +export function request(url: string | url.URL, options: RequestOptions, callback: Callback): void; /** * Handle request with a callback. @@ -154,17 +154,17 @@ export function request(url: string | url.URL, options: IRequestOptions, callbac 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 IRequestOptions. + * @param options Optional, @see RequestOptions. * @param callback @see Callback */ -export function requestWithCallback(url: string | url.URL, options: IRequestOptions, callback: Callback): void; +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 IRequestOptions. + * @param options Optional, @see RequestOptions. */ -export function requestThunk(url: string | url.URL, options: IRequestOptions): (callback: (...args: any[]) => void) => void; +export function requestThunk(url: string | url.URL, options: RequestOptions): (callback: (...args: any[]) => void) => void; /** * alias to request. @@ -178,9 +178,9 @@ export function requestThunk(url: string | url.URL, options: IRequestOptions): ( * 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. + * @param options Optional, @see RequestOptions. */ -export function curl(url: string | url.URL, options?: IRequestOptions): Promise; +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 @@ -188,10 +188,10 @@ export function curl(url: string | url.URL, options?: IRequestOptions): Promise< 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 options Optional, @see RequestOptions. * @param callback @see Callback */ -export function curl(url: string | url.URL, options: IRequestOptions, callback: Callback): void; +export function curl(url: string | url.URL, options: RequestOptions, callback: Callback): void; /** * The default request timeout(in milliseconds). * @const @@ -220,15 +220,15 @@ export const agent: http.Agent; export const httpsAgent: https.Agent; export class HttpClient extends EventEmitter { - constructor(options?: IRequestOptions); + constructor(options?: RequestOptions); request(url: string | url.URL, callback: Callback): void; - request(url: string | url.URL, options: IRequestOptions, 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: IRequestOptions, callback: Callback): void; + curl(url: string | url.URL, options: RequestOptions, callback: Callback): void; - requestThunk(url: string | url.URL, options?: IRequestOptions): (callback: (...args: any[]) => void) => void; + requestThunk(url: string | url.URL, options?: RequestOptions): (callback: (...args: any[]) => void) => void; } /** @@ -236,13 +236,13 @@ export class HttpClient extends EventEmitter { * compatible with async/await and generator in co. */ export class HttpClient2 extends EventEmitter { - constructor(options?: IRequestOptions); + constructor(options?: RequestOptions); - request(url: string | url.URL, options?: IRequestOptions): Promise; + request(url: string | url.URL, options?: RequestOptions): Promise; - curl(url: string | url.URL, options?: IRequestOptions): Promise; + curl(url: string | url.URL, options?: RequestOptions): Promise; - requestThunk(url: string | url.URL, options?: IRequestOptions): (callback: (...args: any[]) => void) => void; + requestThunk(url: string | url.URL, options?: RequestOptions): (callback: (...args: any[]) => void) => void; } /** @@ -250,4 +250,4 @@ export class HttpClient2 extends EventEmitter { * @param options * @return HttpClient incetance. */ -export function create(options?: IRequestOptions): HttpClient; +export function create(options?: RequestOptions): HttpClient; From a45650f75827526bec35f01e0b682d0f12efad5c Mon Sep 17 00:00:00 2001 From: SoraYama Date: Thu, 15 Feb 2018 01:54:46 +0800 Subject: [PATCH 13/15] remove redundant tags and fix the comment --- types/urllib/index.d.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/types/urllib/index.d.ts b/types/urllib/index.d.ts index 4a266cab59..296eacebdf 100644 --- a/types/urllib/index.d.ts +++ b/types/urllib/index.d.ts @@ -141,7 +141,7 @@ export function request(url: string | url.URL, options?: RequestOptions): Promis 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 options @see RequestOptions. * @param callback @see Callback */ export function request(url: string | url.URL, options: RequestOptions, callback: Callback): void; @@ -154,7 +154,7 @@ export function request(url: string | url.URL, options: RequestOptions, 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 options @see RequestOptions. * @param callback @see Callback */ export function requestWithCallback(url: string | url.URL, options: RequestOptions, callback: Callback): void; @@ -164,7 +164,7 @@ export function requestWithCallback(url: string | url.URL, options: RequestOptio * @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; +export function requestThunk(url: string | url.URL, options?: RequestOptions): (callback: (...args: any[]) => void) => void; /** * alias to request. @@ -188,24 +188,21 @@ export function curl(url: string | url.URL, options?: RequestOptions): Promise Date: Thu, 15 Feb 2018 10:02:13 +0800 Subject: [PATCH 14/15] remove redundant return JSDoc tag --- types/urllib/index.d.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/types/urllib/index.d.ts b/types/urllib/index.d.ts index 296eacebdf..f9e7100b8c 100644 --- a/types/urllib/index.d.ts +++ b/types/urllib/index.d.ts @@ -244,7 +244,6 @@ export class HttpClient2 extends EventEmitter { /** * Create a HttpClient incetance. - * @param options - * @return HttpClient incetance. + * @param options @see RequestOptions */ export function create(options?: RequestOptions): HttpClient; From 8724e0c12856a5edbddd82b1afa09ebc1173409c Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 15 Feb 2018 07:14:23 -0800 Subject: [PATCH 15/15] Remove redundant jsdoc --- types/urllib/index.d.ts | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/types/urllib/index.d.ts b/types/urllib/index.d.ts index f9e7100b8c..c6a6f6a46e 100644 --- a/types/urllib/index.d.ts +++ b/types/urllib/index.d.ts @@ -114,7 +114,6 @@ export interface RequestOptions { } /** - * @param err Error * @param data Outgoing message * @param res http response */ @@ -131,38 +130,30 @@ export type Callback = (err: Error, data: any, res: http.IncomingMessage) => voi * 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 @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 @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; @@ -183,13 +174,10 @@ export function requestThunk(url: string | url.URL, options?: 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 @see RequestOptions. - * @param callback @see Callback */ export function curl(url: string | url.URL, options: RequestOptions, callback: Callback): void; /** @@ -243,7 +231,6 @@ export class HttpClient2 extends EventEmitter { } /** - * Create a HttpClient incetance. - * @param options @see RequestOptions + * Create a HttpClient instance. */ export function create(options?: RequestOptions): HttpClient;