From 90fe3e51ea05b90acd58cd65ccc17dd578771b65 Mon Sep 17 00:00:00 2001 From: Javier Date: Tue, 21 Apr 2015 11:14:03 -0700 Subject: [PATCH 01/69] PlayerOptions width and height should be strings, adds Player.destroy() Per https://developers.google.com/youtube/iframe_api_reference PlayerOptions can be other than numbers, in fact in the API reference are created as strings even though they are specified as numbers: '100%' works. Also adds the Player.destroy() method, which removes the iframe from the DOM. --- youtube/youtube.d.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/youtube/youtube.d.ts b/youtube/youtube.d.ts index 85f96b22f..42262f452 100644 --- a/youtube/youtube.d.ts +++ b/youtube/youtube.d.ts @@ -50,8 +50,8 @@ declare module YT { } export interface PlayerOptions { - width?: number; - height?: number; + width?: string; + height?: string; videoId?: string; playerVars?: PlayerVars; events?: Events; @@ -147,6 +147,9 @@ declare module YT { // Event Listener addEventListener(event: string, handler: EventHandler): void; + + // DOM + destroy(): void; } export enum PlayerState { From 729ca9b124a7d4b4631b6295d9ce8f2d848ae4fe Mon Sep 17 00:00:00 2001 From: David Pertiller Date: Mon, 5 Oct 2015 23:23:24 +0200 Subject: [PATCH 02/69] included method definition for onrendered event which provides the rendered canvas element --- html2canvas/html2canvas.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/html2canvas/html2canvas.d.ts b/html2canvas/html2canvas.d.ts index 689421971..61eba51fd 100644 --- a/html2canvas/html2canvas.d.ts +++ b/html2canvas/html2canvas.d.ts @@ -37,6 +37,8 @@ declare module Html2Canvas { /** Whether to attempt to load cross-origin images as CORS served, before reverting back to proxy. */ useCORS?: boolean; + /** Callback providing the rendered canvas element after rendering */ + onrendered?(canvas: HTMLElement): void; } } From 202d240a0a0c86661b30f3a97169e70f72484293 Mon Sep 17 00:00:00 2001 From: Joe Skeen Date: Wed, 7 Oct 2015 09:07:44 -0600 Subject: [PATCH 03/69] 'request': Added more tests from project page and fixed definitions accordingly --- request/request-tests.ts | 438 ++++++++++++++++++++++++++++++++++++++- request/request.d.ts | 146 ++++++++----- 2 files changed, 517 insertions(+), 67 deletions(-) diff --git a/request/request-tests.ts b/request/request-tests.ts index 9d7cbf3bc..7f04be26a 100644 --- a/request/request-tests.ts +++ b/request/request-tests.ts @@ -4,6 +4,7 @@ import request = require('request'); import http = require('http'); import stream = require('stream'); import formData = require('form-data'); +import fs = require('fs'); var value: any; var str: string; @@ -20,7 +21,7 @@ var headers: {[key: string]: string}; var agent: http.Agent; var write: stream.Writable; var req: request.Request; -var form: formData.FormData; +var form1: formData.FormData; var bodyArr: request.RequestPart[] = [{ body: value @@ -125,8 +126,6 @@ req.destroy(); // --- --- --- --- --- --- --- --- --- --- --- --- -var callback: (error: any, response: any, body: any) => void; - value = request.initParams; req = request(uri); @@ -136,13 +135,6 @@ req = request(uri, callback); req = request(options); req = request(options, callback); -req = request.request(uri); -req = request.request(uri, options); -req = request.request(uri, options, callback); -req = request.request(uri, callback); -req = request.request(options); -req = request.request(options, callback); - req = request.get(uri); req = request.get(uri, options); req = request.get(uri, options, callback); @@ -204,3 +196,429 @@ request // check response }) .pipe(request.put('http://another.com/another.png')); + +//The following examples from https://github.com/request/request +request('http://www.google.com', function (error, response, body) { + if (!error && response.statusCode == 200) { + console.log(body); // Show the HTML for the Google homepage. + } +}); + +request('http://google.com/doodle.png').pipe(fs.createWriteStream('doodle.png')); + +fs.createReadStream('file.json').pipe(request.put('http://mysite.com/obj.json')); + +request.get('http://google.com/img.png').pipe(request.put('http://mysite.com/img.png')); + +request + .get('http://google.com/img.png') + .on('response', function(response) { + console.log(response.statusCode); // 200 + console.log(response.headers['content-type']); // 'image/png' + }) + .pipe(request.put('http://mysite.com/img.png')); + +request + .get('http://mysite.com/doodle.png') + .on('error', function(err) { + console.log(err); + }) + .pipe(fs.createWriteStream('doodle.png')); + +http.createServer(function (req, resp) { + if (req.url === '/doodle.png') { + if (req.method === 'PUT') { + req.pipe(request.put('http://mysite.com/doodle.png')); + } else if (req.method === 'GET' || req.method === 'HEAD') { + request.get('http://mysite.com/doodle.png').pipe(resp); + } + } +}); + +http.createServer(function (req, resp) { + if (req.url === '/doodle.png') { + var x = request('http://mysite.com/doodle.png'); + req.pipe(x); + x.pipe(resp); + } +}); + +var resp: http.ServerResponse; +req.pipe(request('http://mysite.com/doodle.png')).pipe(resp); + +http.createServer(function (req, resp) { + if (req.url === '/doodle.png') { + r.get('http://google.com/doodle.png').pipe(resp); + } +}); + +request.post('http://service.com/upload', {form:{key:'value'}}); +// or +request.post('http://service.com/upload').form({key:'value'}); +// or +request.post({url:'http://service.com/upload', form: {key:'value'}}, function(err,httpResponse,body){ /* ... */ }); + +var data = { + // Pass a simple key-value pair + my_field: 'my_value', + // Pass data via Buffers + my_buffer: new Buffer([1, 2, 3]), + // Pass data via Streams + my_file: fs.createReadStream(__dirname + '/unicycle.jpg'), + // Pass multiple values /w an Array + attachments: [ + fs.createReadStream(__dirname + '/attachment1.jpg'), + fs.createReadStream(__dirname + '/attachment2.jpg') + ], + // Pass optional meta-data with an 'options' object with style: {value: DATA, options: OPTIONS} + // Use case: for some types of streams, you'll need to provide "file"-related information manually. + // See the `form-data` README for more information about options: https://github.com/felixge/node-form-data + custom_file: { + value: fs.createReadStream('/dev/urandom'), + options: { + filename: 'topsecret.jpg', + contentType: 'image/jpg' + } + } +}; +request.post({url:'http://service.com/upload', formData: data}, function optionalCallback(err, httpResponse, body) { + if (err) { + return console.error('upload failed:', err); + } + console.log('Upload successful! Server responded with:', body); +}); + +var requestMultipart = request.post('http://service.com/upload', function optionalCallback(err, httpResponse, body) {}); +var form = requestMultipart.form(); +form.append('my_field', 'my_value'); +form.append('my_buffer', new Buffer([1, 2, 3])); +form.append('custom_file', fs.createReadStream(__dirname + '/unicycle.jpg'), {filename: 'unicycle.jpg'}); + +request({ + method: 'PUT', + preambleCRLF: true, + postambleCRLF: true, + uri: 'http://service.com/upload', + multipart: { + chunked: false, + data: [ + { + 'content-type': 'application/json', + body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}}) + }, + { body: 'I am an attachment' } + ] + } + }, + function (error, response, body) { + if (error) { + return console.error('upload failed:', error); + } + console.log('Upload successful! Server responded with:', body); + }); +request({ + method: 'PUT', + preambleCRLF: true, + postambleCRLF: true, + uri: 'http://service.com/upload', + multipart: [ + { + 'content-type': 'application/json', + body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}}) + }, + { body: 'I am an attachment' }, + { body: fs.createReadStream('image.png') } + ] + }, + function (error, response, body) { + if (error) { + return console.error('upload failed:', error); + } + console.log('Upload successful! Server responded with:', body); + }); + +request.get('http://some.server.com/').auth('username', 'password', false); +// or +request.get('http://some.server.com/', { + 'auth': { + 'user': 'username', + 'pass': 'password', + 'sendImmediately': false + } +}); +// or +request.get('http://some.server.com/').auth(null, null, true, 'bearerToken'); +// or +request.get('http://some.server.com/', { + 'auth': { + 'bearer': 'bearerToken' + } +}); + +var username = 'username', + password = 'password', + url = 'http://' + username + ':' + password + '@some.server.com'; + +request({url: url}, function (error, response, body) { + // Do more stuff with 'body' here +}); + +options = { + url: 'https://api.github.com/repos/request/request', + headers: { + 'User-Agent': 'request' + } +}; + +function callback(error, response, body) { + if (!error && response.statusCode == 200) { + var info = JSON.parse(body); + console.log(info.stargazers_count + " Stars"); + console.log(info.forks_count + " Forks"); + } +} + +request(options, callback); + +// OAuth1.0 - 3-legged server side flow (Twitter example) +// step 1 +import qs = require('querystring'); +const CONSUMER_KEY = 'key'; +const CONSUMER_SECRET = 'secret'; +oauth = + { callback: 'http://mysite.com/callback/' + , consumer_key: CONSUMER_KEY + , consumer_secret: CONSUMER_SECRET + } + , url = 'https://api.twitter.com/oauth/request_token' + ; +request.post({url:url, oauth:oauth}, function (e, r, body) { + // Ideally, you would take the body in the response + // and construct a URL that a user clicks on (like a sign in button). + // The verifier is only available in the response after a user has + // verified with twitter that they are authorizing your app. + + // step 2 + var req_data = qs.parse(body); + var uri = 'https://api.twitter.com/oauth/authenticate' + + '?' + qs.stringify({oauth_token: req_data.oauth_token}); + // redirect the user to the authorize uri + + // step 3 + // after the user is redirected back to your server + var auth_data = qs.parse(body) + , oauth = + { consumer_key: CONSUMER_KEY + , consumer_secret: CONSUMER_SECRET + , token: auth_data.oauth_token + , token_secret: req_data.oauth_token_secret + , verifier: auth_data.oauth_verifier + } + , url = 'https://api.twitter.com/oauth/access_token' + ; + request.post({url:url, oauth:oauth}, function (e, r, body) { + // ready to make signed requests on behalf of the user + var perm_data = qs.parse(body) + , oauth = + { consumer_key: CONSUMER_KEY + , consumer_secret: CONSUMER_SECRET + , token: perm_data.oauth_token + , token_secret: perm_data.oauth_token_secret + } + , url = 'https://api.twitter.com/1.1/users/show.json' + , qs = + { screen_name: perm_data.screen_name + , user_id: perm_data.user_id + } + ; + request.get({url:url, oauth:oauth, qs:qs, json:true}, function (e, r, user) { + console.log(user); + }); + }); +}); + +var path = require('path') + , certFile = path.resolve(__dirname, 'ssl/client.crt') + , keyFile = path.resolve(__dirname, 'ssl/client.key') + , caFile = path.resolve(__dirname, 'ssl/ca.cert.pem'); + +options = { + url: 'https://api.some-server.com/', + cert: fs.readFileSync(certFile), + key: fs.readFileSync(keyFile), + passphrase: 'password', + ca: fs.readFileSync(caFile) +}; + +request.get(options); + +var path = require('path') + , certFile = path.resolve(__dirname, 'ssl/client.crt') + , keyFile = path.resolve(__dirname, 'ssl/client.key'); + +options = { + url: 'https://api.some-server.com/', + agentOptions: { + cert: fs.readFileSync(certFile), + key: fs.readFileSync(keyFile), + // Or use `pfx` property replacing `cert` and `key` when using private key, certificate and CA certs in PFX or PKCS12 format: + // pfx: fs.readFileSync(pfxFilePath), + passphrase: 'password', + securityOptions: 'SSL_OP_NO_SSLv3' + } +}; + +request.get(options); + +request.get({ + url: 'https://api.some-server.com/', + agentOptions: { + secureProtocol: 'SSLv3_method' + } +}); + +request.get({ + url: 'https://api.some-server.com/', + agentOptions: { + ca: fs.readFileSync('ca.cert.pem') + } +}); + + +request({ + // will be ignored + method: 'GET', + uri: 'http://www.google.com', + + // HTTP Archive Request Object + har: { + url: 'http://www.mockbin.com/har', + method: 'POST', + headers: [ + { + name: 'content-type', + value: 'application/x-www-form-urlencoded' + } + ], + postData: { + mimeType: 'application/x-www-form-urlencoded', + params: [ + { + name: 'foo', + value: 'bar' + }, + { + name: 'hello', + value: 'world' + } + ] + } + } + }); + +//requests using baseRequest() will set the 'x-token' header +var baseRequest = request.defaults({ + headers: {'x-token': 'my-token'} +}); + +//requests using specialRequest() will include the 'x-token' header set in +//baseRequest and will also include the 'special' header +var specialRequest = baseRequest.defaults({ + headers: {special: 'special value'} +}); + +request.put(url); +request.patch(url); +request.post(url); +request.head(url); +request.del(url); +request.get(url); +request.cookie('key1=value1'); +request.jar(); +request.debug = true; + +request.get('http://10.255.255.1', {timeout: 1500}, function(err) { + console.log(err.code === 'ETIMEDOUT'); + // Set to `true` if the timeout was a connection timeout, `false` or + // `undefined` otherwise. + console.log(err.connect === true); + process.exit(0); +}); + +var rand = Math.floor(Math.random()*100000000).toString(); + request( + { method: 'PUT' + , uri: 'http://mikeal.iriscouch.com/testjs/' + rand + , multipart: + [ { 'content-type': 'application/json' + , body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}}) + } + , { body: 'I am an attachment' } + ] + } + , function (error, response, body) { + if(response.statusCode == 201){ + console.log('document saved as: http://mikeal.iriscouch.com/testjs/'+ rand) + } else { + console.log('error: '+ response.statusCode) + console.log(body) + } + } + ); + +request( + { method: 'GET' + , uri: 'http://www.google.com' + , gzip: true + } + , function (error, response, body) { + // body is the decompressed response body + console.log('server encoded the data as: ' + (response.headers['content-encoding'] || 'identity')) + console.log('the decoded data is: ' + body) + } + ).on('data', function(data) { + // decompressed data as it is received + console.log('decoded chunk: ' + data) + }) + .on('response', function(response) { + // unmodified http.IncomingMessage object + response.on('data', function(data) { + // compressed data as it is received + console.log('received ' + data.length + ' bytes of compressed data') + }) + }); + +var requestWithJar = request.defaults({jar: true}) +requestWithJar('http://www.google.com', function () { + requestWithJar('http://images.google.com'); +}); + +var j = request.jar() +requestWithJar = request.defaults({jar:j}) +requestWithJar('http://www.google.com', function () { + requestWithJar('http://images.google.com'); +}); + +var j = request.jar(); +cookie = request.cookie('key1=value1'); +var url = 'http://www.google.com'; +j.setCookie(cookie, url); +request({url: url, jar: j}, function () { + request('http://images.google.com'); +}); + +//TODO: add definitions for tough-cookie-filestore +//var FileCookieStore = require('tough-cookie-filestore'); +// NOTE - currently the 'cookies.json' file must already exist! +//var j = request.jar(new FileCookieStore('cookies.json')); +requestWithJar = request.defaults({ jar : j }) +request('http://www.google.com', function() { + request('http://images.google.com'); +}); + +var j = request.jar() +request({url: 'http://www.google.com', jar: j}, function () { + var cookie_string = j.getCookieString(url); // "key1=value1; key2=value2; ..." + var cookies = j.getCookies(url); + // [{key: 'key1', value: 'value1', domain: "www.google.com", ...}, ...] +}); diff --git a/request/request.d.ts b/request/request.d.ts index 4827bc7a6..f3a2741fb 100644 --- a/request/request.d.ts +++ b/request/request.d.ts @@ -13,50 +13,50 @@ declare module 'request' { import http = require('http'); import FormData = require('form-data'); import url = require('url'); + import fs = require('fs'); - export = RequestAPI; - - function RequestAPI(uri: string, options?: RequestAPI.Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): RequestAPI.Request; - function RequestAPI(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): RequestAPI.Request; - function RequestAPI(options: RequestAPI.Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): RequestAPI.Request; - - module RequestAPI { - export function defaults(options: Options): typeof RequestAPI; - - export function request(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - export function request(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - export function request(options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - - export function get(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - export function get(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - export function get(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - - export function post(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - export function post(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - export function post(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - - export function put(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - export function put(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - export function put(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - - export function head(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - export function head(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - export function head(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - - export function patch(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - export function patch(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - export function patch(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - - export function del(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - export function del(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - export function del(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - - export function forever(agentOptions: any, optionsArg: any): Request; - export function jar(): CookieJar; - export function cookie(str: string): Cookie; - - export var initParams: any; - + namespace request { + export interface RequestAPI { + defaults(options: Options): RequestAPI; + (uri: string, + options?: Options, + callback?: (error: any, response: http.IncomingMessage, body: any) => void) + : Request; + (uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + (options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + + get(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + get(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + get(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + + post(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + post(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + post(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + + put(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + put(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + put(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + + head(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + head(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + head(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + + patch(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + patch(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + patch(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + + del(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + del(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + del(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + + forever(agentOptions: any, optionsArg: any): Request; + jar(): CookieJar; + cookie(str: string): Cookie; + + initParams: any; + debug: boolean; + } + export interface Options { url?: string; uri?: string; @@ -70,7 +70,7 @@ declare module 'request' { hawk ?: HawkOptions; qs?: any; json?: any; - multipart?: RequestPart[]; + multipart?: RequestPart[] | Multipart; agentOptions?: any; agentClass?: any; forever?: any; @@ -88,17 +88,47 @@ declare module 'request' { proxy?: any; strictSSL?: boolean; gzip?: boolean; + preambleCRLF?: boolean; + postambleCRLF?: boolean; + key?: Buffer; + cert?: Buffer; + passphrase?: string; + ca?: Buffer; + har?: HttpArchiveRequest; } + + export interface HttpArchiveRequest { + url?: string; + method?: string; + headers?: NameValuePair[]; + postData?: { + mimeType?: string; + params?: NameValuePair[]; + } + } + export interface NameValuePair { + name: string; + value: string; + } + + export interface Multipart { + chunked?: boolean; + data?: { + 'content-type'?: string, + body: string + }[]; + } + export interface RequestPart { headers?: Headers; body: any; } - + export interface Request extends stream.Stream { readable: boolean; writable: boolean; - + getAgent(): http.Agent; //start(): void; //abort(): void; @@ -114,9 +144,9 @@ declare module 'request' { auth(username: string, password: string, sendInmediately?: boolean, bearer?: string): Request; oauth(oauth: OAuthOptions): Request; jar(jar: CookieJar): Request; - + on(event: string, listener: Function): Request; - + write(buffer: Buffer, cb?: Function): boolean; write(str: string, cb?: Function): boolean; write(str: string, encoding: string, cb?: Function): boolean; @@ -131,11 +161,11 @@ declare module 'request' { destroy(): void; toJSON(): string; } - + export interface Headers { [key: string]: any; } - + export interface AuthOptions { user?: string; username?: string; @@ -144,7 +174,7 @@ declare module 'request' { sendImmediately?: boolean; bearer?: string; } - + export interface OAuthOptions { callback?: string; consumer_key?: string; @@ -153,28 +183,28 @@ declare module 'request' { token_secret?: string; verifier?: string; } - + export interface HawkOptions { credentials: any; } - + export interface AWSOptions { secret: string; bucket?: string; } - + export interface CookieJar { setCookie(cookie: Cookie, uri: string|url.Url, options?: any): void getCookieString(uri: string|url.Url): string getCookies(uri: string|url.Url): Cookie[] } - + export interface CookieValue { name: string; value: any; httpOnly: boolean; } - + export interface Cookie extends Array { constructor(name: string, req: Request): void; str: string; @@ -182,5 +212,7 @@ declare module 'request' { path: string; toString(): string; } - } + } + var request: request.RequestAPI; + export = request; } From 31d1cc43cd5f828fec19f35c286396f859fa47cc Mon Sep 17 00:00:00 2001 From: Joe Skeen Date: Wed, 7 Oct 2015 09:41:45 -0600 Subject: [PATCH 04/69] Change request-promise to use full 'request' API --- request-promise/request-promise-tests.ts | 453 ++++++++++++++++++++++- request-promise/request-promise.d.ts | 25 +- request/request-tests.ts | 2 +- request/request.d.ts | 54 +-- 4 files changed, 486 insertions(+), 48 deletions(-) diff --git a/request-promise/request-promise-tests.ts b/request-promise/request-promise-tests.ts index 41a5eb80d..ad2f8f61f 100644 --- a/request-promise/request-promise-tests.ts +++ b/request-promise/request-promise-tests.ts @@ -1,17 +1,466 @@ /// import rp = require('request-promise'); +import nodeRequest = require('request'); rp('http://www.google.com') .then(console.dir) .catch(console.error); -var options: rp.Options = { +var options: nodeRequest.Options = { uri : 'http://posttestserver.com/post.php', - method : 'POST' + method : 'POST', + json: true, + body: { some: 'payload' } }; rp(options) .then(console.dir) .catch(console.error); +// --> Displays length of response from server after post + +// Get full response after DELETE +options = { + method: 'DELETE', + uri: 'http://my-server/path/to/resource/1234' +}; + +rp(options) + .then(function (response) { + console.log("DELETE succeeded with status %d", response.statusCode); + }) + .catch(console.error); + +//The following examples from https://github.com/request/request +import fs = require('fs'); +import http = require('http'); +var request = rp; + +//The following examples from https://github.com/request/request +request('http://www.google.com', function (error, response, body) { + if (!error && response.statusCode == 200) { + console.log(body); // Show the HTML for the Google homepage. + } +}); + +request('http://google.com/doodle.png').pipe(fs.createWriteStream('doodle.png')); + +fs.createReadStream('file.json').pipe(request.put('http://mysite.com/obj.json')); + +request.get('http://google.com/img.png').pipe(request.put('http://mysite.com/img.png')); + +request + .get('http://google.com/img.png') + .on('response', function(response) { + console.log(response.statusCode); // 200 + console.log(response.headers['content-type']); // 'image/png' + }) + .pipe(request.put('http://mysite.com/img.png')); + +request + .get('http://mysite.com/doodle.png') + .on('error', function(err) { + console.log(err); + }) + .pipe(fs.createWriteStream('doodle.png')); + +http.createServer(function (req, resp) { + if (req.url === '/doodle.png') { + if (req.method === 'PUT') { + req.pipe(request.put('http://mysite.com/doodle.png')); + } else if (req.method === 'GET' || req.method === 'HEAD') { + request.get('http://mysite.com/doodle.png').pipe(resp); + } + } +}); + +http.createServer(function (req, resp) { + if (req.url === '/doodle.png') { + var x = request('http://mysite.com/doodle.png'); + req.pipe(x); + x.pipe(resp); + } +}); + +var resp: http.ServerResponse; +var req: nodeRequest.Request; +req.pipe(request('http://mysite.com/doodle.png')).pipe(resp); + +var r = request; +http.createServer(function (req, resp) { + if (req.url === '/doodle.png') { + r.get('http://google.com/doodle.png').pipe(resp); + } +}); + +request.post('http://service.com/upload', {form:{key:'value'}}); +// or +request.post('http://service.com/upload').form({key:'value'}); +// or +request.post({url:'http://service.com/upload', form: {key:'value'}}, function(err,httpResponse,body){ /* ... */ }); + +var data = { + // Pass a simple key-value pair + my_field: 'my_value', + // Pass data via Buffers + my_buffer: new Buffer([1, 2, 3]), + // Pass data via Streams + my_file: fs.createReadStream(__dirname + '/unicycle.jpg'), + // Pass multiple values /w an Array + attachments: [ + fs.createReadStream(__dirname + '/attachment1.jpg'), + fs.createReadStream(__dirname + '/attachment2.jpg') + ], + // Pass optional meta-data with an 'options' object with style: {value: DATA, options: OPTIONS} + // Use case: for some types of streams, you'll need to provide "file"-related information manually. + // See the `form-data` README for more information about options: https://github.com/felixge/node-form-data + custom_file: { + value: fs.createReadStream('/dev/urandom'), + options: { + filename: 'topsecret.jpg', + contentType: 'image/jpg' + } + } +}; +request.post({url:'http://service.com/upload', formData: data}, function optionalCallback(err, httpResponse, body) { + if (err) { + return console.error('upload failed:', err); + } + console.log('Upload successful! Server responded with:', body); +}); + +var requestMultipart = request.post('http://service.com/upload', function optionalCallback(err, httpResponse, body) {}); +var form = requestMultipart.form(); +form.append('my_field', 'my_value'); +form.append('my_buffer', new Buffer([1, 2, 3])); +form.append('custom_file', fs.createReadStream(__dirname + '/unicycle.jpg'), {filename: 'unicycle.jpg'}); + +request({ + method: 'PUT', + preambleCRLF: true, + postambleCRLF: true, + uri: 'http://service.com/upload', + multipart: { + chunked: false, + data: [ + { + 'content-type': 'application/json', + body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}}) + }, + { body: 'I am an attachment' } + ] + } + }, + function (error, response, body) { + if (error) { + return console.error('upload failed:', error); + } + console.log('Upload successful! Server responded with:', body); + }); +request({ + method: 'PUT', + preambleCRLF: true, + postambleCRLF: true, + uri: 'http://service.com/upload', + multipart: [ + { + 'content-type': 'application/json', + body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}}) + }, + { body: 'I am an attachment' }, + { body: fs.createReadStream('image.png') } + ] + }, + function (error, response, body) { + if (error) { + return console.error('upload failed:', error); + } + console.log('Upload successful! Server responded with:', body); + }); + +request.get('http://some.server.com/').auth('username', 'password', false); +// or +request.get('http://some.server.com/', { + 'auth': { + 'user': 'username', + 'pass': 'password', + 'sendImmediately': false + } +}); +// or +request.get('http://some.server.com/').auth(null, null, true, 'bearerToken'); +// or +request.get('http://some.server.com/', { + 'auth': { + 'bearer': 'bearerToken' + } +}); + +var username = 'username', + password = 'password', + url = 'http://' + username + ':' + password + '@some.server.com'; + +request({url: url}, function (error, response, body) { + // Do more stuff with 'body' here +}); + +options = { + url: 'https://api.github.com/repos/request/request', + headers: { + 'User-Agent': 'request' + } +}; + +function callback(error, response, body) { + if (!error && response.statusCode == 200) { + var info = JSON.parse(body); + console.log(info.stargazers_count + " Stars"); + console.log(info.forks_count + " Forks"); + } +} + +request(options, callback); + +// OAuth1.0 - 3-legged server side flow (Twitter example) +// step 1 +import qs = require('querystring'); +const CONSUMER_KEY = 'key'; +const CONSUMER_SECRET = 'secret'; +var oauth = + { callback: 'http://mysite.com/callback/' + , consumer_key: CONSUMER_KEY + , consumer_secret: CONSUMER_SECRET + } + , url = 'https://api.twitter.com/oauth/request_token' + ; +request.post({url:url, oauth:oauth}, function (e, r, body) { + // Ideally, you would take the body in the response + // and construct a URL that a user clicks on (like a sign in button). + // The verifier is only available in the response after a user has + // verified with twitter that they are authorizing your app. + + // step 2 + var req_data = qs.parse(body); + var uri = 'https://api.twitter.com/oauth/authenticate' + + '?' + qs.stringify({oauth_token: req_data.oauth_token}); + // redirect the user to the authorize uri + + // step 3 + // after the user is redirected back to your server + var auth_data = qs.parse(body) + , oauth = + { consumer_key: CONSUMER_KEY + , consumer_secret: CONSUMER_SECRET + , token: auth_data.oauth_token + , token_secret: req_data.oauth_token_secret + , verifier: auth_data.oauth_verifier + } + , url = 'https://api.twitter.com/oauth/access_token' + ; + request.post({url:url, oauth:oauth}, function (e, r, body) { + // ready to make signed requests on behalf of the user + var perm_data = qs.parse(body) + , oauth = + { consumer_key: CONSUMER_KEY + , consumer_secret: CONSUMER_SECRET + , token: perm_data.oauth_token + , token_secret: perm_data.oauth_token_secret + } + , url = 'https://api.twitter.com/1.1/users/show.json' + , qs = + { screen_name: perm_data.screen_name + , user_id: perm_data.user_id + } + ; + request.get({url:url, oauth:oauth, qs:qs, json:true}, function (e, r, user) { + console.log(user); + }); + }); +}); + +var path = require('path') + , certFile = path.resolve(__dirname, 'ssl/client.crt') + , keyFile = path.resolve(__dirname, 'ssl/client.key') + , caFile = path.resolve(__dirname, 'ssl/ca.cert.pem'); + +options = { + url: 'https://api.some-server.com/', + cert: fs.readFileSync(certFile), + key: fs.readFileSync(keyFile), + passphrase: 'password', + ca: fs.readFileSync(caFile) +}; + +request.get(options); + +var path = require('path') + , certFile = path.resolve(__dirname, 'ssl/client.crt') + , keyFile = path.resolve(__dirname, 'ssl/client.key'); + +options = { + url: 'https://api.some-server.com/', + agentOptions: { + cert: fs.readFileSync(certFile), + key: fs.readFileSync(keyFile), + // Or use `pfx` property replacing `cert` and `key` when using private key, certificate and CA certs in PFX or PKCS12 format: + // pfx: fs.readFileSync(pfxFilePath), + passphrase: 'password', + securityOptions: 'SSL_OP_NO_SSLv3' + } +}; + +request.get(options); + +request.get({ + url: 'https://api.some-server.com/', + agentOptions: { + secureProtocol: 'SSLv3_method' + } +}); + +request.get({ + url: 'https://api.some-server.com/', + agentOptions: { + ca: fs.readFileSync('ca.cert.pem') + } +}); + + +request({ + // will be ignored + method: 'GET', + uri: 'http://www.google.com', + + // HTTP Archive Request Object + har: { + url: 'http://www.mockbin.com/har', + method: 'POST', + headers: [ + { + name: 'content-type', + value: 'application/x-www-form-urlencoded' + } + ], + postData: { + mimeType: 'application/x-www-form-urlencoded', + params: [ + { + name: 'foo', + value: 'bar' + }, + { + name: 'hello', + value: 'world' + } + ] + } + } + }); + +//requests using baseRequest() will set the 'x-token' header +var baseRequest = request.defaults({ + headers: {'x-token': 'my-token'} +}); + +//requests using specialRequest() will include the 'x-token' header set in +//baseRequest and will also include the 'special' header +var specialRequest = baseRequest.defaults({ + headers: {special: 'special value'} +}); + +request.put(url); +request.patch(url); +request.post(url); +request.head(url); +request.del(url); +request.get(url); +request.cookie('key1=value1'); +request.jar(); +request.debug = true; + +request.get('http://10.255.255.1', {timeout: 1500}, function(err) { + console.log(err.code === 'ETIMEDOUT'); + // Set to `true` if the timeout was a connection timeout, `false` or + // `undefined` otherwise. + console.log(err.connect === true); + process.exit(0); +}); + +var rand = Math.floor(Math.random()*100000000).toString(); + request( + { method: 'PUT' + , uri: 'http://mikeal.iriscouch.com/testjs/' + rand + , multipart: + [ { 'content-type': 'application/json' + , body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}}) + } + , { body: 'I am an attachment' } + ] + } + , function (error, response, body) { + if(response.statusCode == 201){ + console.log('document saved as: http://mikeal.iriscouch.com/testjs/'+ rand) + } else { + console.log('error: '+ response.statusCode) + console.log(body) + } + } + ); + +request( + { method: 'GET' + , uri: 'http://www.google.com' + , gzip: true + } + , function (error, response, body) { + // body is the decompressed response body + console.log('server encoded the data as: ' + (response.headers['content-encoding'] || 'identity')) + console.log('the decoded data is: ' + body) + } + ).on('data', function(data) { + // decompressed data as it is received + console.log('decoded chunk: ' + data) + }) + .on('response', function(response) { + // unmodified http.IncomingMessage object + response.on('data', function(data) { + // compressed data as it is received + console.log('received ' + data.length + ' bytes of compressed data') + }) + }); + +var requestWithJar = request.defaults({jar: true}) +requestWithJar('http://www.google.com', function () { + requestWithJar('http://images.google.com'); +}); + +var j = request.jar() +requestWithJar = request.defaults({jar:j}) +requestWithJar('http://www.google.com', function () { + requestWithJar('http://images.google.com'); +}); + +var j = request.jar(); +var cookie = request.cookie('key1=value1'); +var url = 'http://www.google.com'; +j.setCookie(cookie, url); +request({url: url, jar: j}, function () { + request('http://images.google.com'); +}); + +//TODO: add definitions for tough-cookie-filestore +//var FileCookieStore = require('tough-cookie-filestore'); +// NOTE - currently the 'cookies.json' file must already exist! +//var j = request.jar(new FileCookieStore('cookies.json')); +requestWithJar = request.defaults({ jar : j }) +request('http://www.google.com', function() { + request('http://images.google.com'); +}); + +var j = request.jar() +request({url: 'http://www.google.com', jar: j}, function () { + var cookie_string = j.getCookieString(url); // "key1=value1; key2=value2; ..." + var cookies = j.getCookies(url); + // [{key: 'key1', value: 'value1', domain: "www.google.com", ...}, ...] +}); diff --git a/request-promise/request-promise.d.ts b/request-promise/request-promise.d.ts index 246f1e5d9..67b82ebd8 100644 --- a/request-promise/request-promise.d.ts +++ b/request-promise/request-promise.d.ts @@ -1,31 +1,20 @@ // Type definitions for request-promise v0.4.2 // Project: https://www.npmjs.com/package/request-promise -// Definitions by: Christopher Glantschnig +// Definitions by: Christopher Glantschnig , Joe Skeen // Definitions: https://github.com/borisyankov/DefinitelyTyped // Change [0]: 2015/08/20 - Aya Morisawa -/// -/// /// /// declare module 'request-promise' { import request = require('request'); - import stream = require('stream'); - import http = require('http'); - import FormData = require('form-data'); - - export = RequestPromiseAPI; - - function RequestPromiseAPI(options: RequestPromiseAPI.Options): Promise; - function RequestPromiseAPI(uri: string): Promise; - - module RequestPromiseAPI { - export interface Options extends request.Options { - simple?: boolean; - transform?: (body: any, response: http.IncomingMessage) => any; - resolveWithFullResponse?: boolean; - } + import http = require('http'); + + interface RequestPromise extends request.Request, Promise { } + + var requestPromise: request.RequestAPI; + export = requestPromise; } diff --git a/request/request-tests.ts b/request/request-tests.ts index 7f04be26a..99c7f566c 100644 --- a/request/request-tests.ts +++ b/request/request-tests.ts @@ -33,7 +33,7 @@ var bodyArr: request.RequestPart[] = [{ // --- --- --- --- --- --- --- --- --- --- --- --- -str = req.toJSON(); +obj = req.toJSON(); var cookieValue: request.CookieValue; str = cookieValue.name; diff --git a/request/request.d.ts b/request/request.d.ts index f3a2741fb..202adf955 100644 --- a/request/request.d.ts +++ b/request/request.d.ts @@ -1,6 +1,6 @@ // Type definitions for request // Project: https://github.com/mikeal/request -// Definitions by: Carlos Ballesteros Velasco , bonnici , Bart van der Schoor +// Definitions by: Carlos Ballesteros Velasco , bonnici , Bart van der Schoor , Joe Skeen // Definitions: https://github.com/borisyankov/DefinitelyTyped // Imported from: https://github.com/soywiz/typescript-node-definitions/d.ts @@ -16,40 +16,40 @@ declare module 'request' { import fs = require('fs'); namespace request { - export interface RequestAPI { - defaults(options: Options): RequestAPI; + export interface RequestAPI { + defaults(options: Options): RequestAPI; (uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void) - : Request; - (uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - (options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + : TRequest; + (uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; + (options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; - get(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - get(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - get(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + get(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; + get(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; + get(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; - post(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - post(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - post(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + post(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; + post(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; + post(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; - put(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - put(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - put(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + put(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; + put(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; + put(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; - head(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - head(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - head(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + head(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; + head(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; + head(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; - patch(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - patch(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - patch(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + patch(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; + patch(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; + patch(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; - del(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - del(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; - del(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request; + del(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; + del(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; + del(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; - forever(agentOptions: any, optionsArg: any): Request; + forever(agentOptions: any, optionsArg: any): TRequest; jar(): CookieJar; cookie(str: string): Cookie; @@ -159,7 +159,7 @@ declare module 'request' { resume(): void; abort(): void; destroy(): void; - toJSON(): string; + toJSON(): Object; } export interface Headers { @@ -213,6 +213,6 @@ declare module 'request' { toString(): string; } } - var request: request.RequestAPI; + var request: request.RequestAPI; export = request; } From b06d25ff7a01af49ca934962021de73f4d292818 Mon Sep 17 00:00:00 2001 From: Joe Skeen Date: Wed, 7 Oct 2015 10:01:23 -0600 Subject: [PATCH 05/69] Fix implicit any issues --- request-promise/request-promise-tests.ts | 34 ++++++++-------- request/request-tests.ts | 33 ++++++++-------- request/request.d.ts | 49 ++++++++++++------------ 3 files changed, 57 insertions(+), 59 deletions(-) diff --git a/request-promise/request-promise-tests.ts b/request-promise/request-promise-tests.ts index ad2f8f61f..a4d28a8f4 100644 --- a/request-promise/request-promise-tests.ts +++ b/request-promise/request-promise-tests.ts @@ -37,7 +37,6 @@ import fs = require('fs'); import http = require('http'); var request = rp; -//The following examples from https://github.com/request/request request('http://www.google.com', function (error, response, body) { if (!error && response.statusCode == 200) { console.log(body); // Show the HTML for the Google homepage. @@ -52,7 +51,7 @@ request.get('http://google.com/img.png').pipe(request.put('http://mysite.com/img request .get('http://google.com/img.png') - .on('response', function(response) { + .on('response', function(response: any) { console.log(response.statusCode); // 200 console.log(response.headers['content-type']); // 'image/png' }) @@ -60,7 +59,7 @@ request request .get('http://mysite.com/doodle.png') - .on('error', function(err) { + .on('error', function(err: any) { console.log(err); }) .pipe(fs.createWriteStream('doodle.png')); @@ -212,7 +211,7 @@ options = { } }; -function callback(error, response, body) { +function callback(error: any, response: http.IncomingMessage, body: string) { if (!error && response.statusCode == 200) { var info = JSON.parse(body); console.log(info.stargazers_count + " Stars"); @@ -248,7 +247,7 @@ request.post({url:url, oauth:oauth}, function (e, r, body) { // step 3 // after the user is redirected back to your server - var auth_data = qs.parse(body) + var auth_data: any = qs.parse(body) , oauth = { consumer_key: CONSUMER_KEY , consumer_secret: CONSUMER_SECRET @@ -260,20 +259,19 @@ request.post({url:url, oauth:oauth}, function (e, r, body) { ; request.post({url:url, oauth:oauth}, function (e, r, body) { // ready to make signed requests on behalf of the user - var perm_data = qs.parse(body) - , oauth = + var perm_data: any = qs.parse(body); + var oauth = { consumer_key: CONSUMER_KEY , consumer_secret: CONSUMER_SECRET , token: perm_data.oauth_token , token_secret: perm_data.oauth_token_secret - } - , url = 'https://api.twitter.com/1.1/users/show.json' - , qs = - { screen_name: perm_data.screen_name - , user_id: perm_data.user_id - } - ; - request.get({url:url, oauth:oauth, qs:qs, json:true}, function (e, r, user) { + }; + var url = 'https://api.twitter.com/1.1/users/show.json'; + var query = { + screen_name: perm_data.screen_name, + user_id: perm_data.user_id + }; + request.get({url:url, oauth:oauth, qs:query, json:true}, function (e, r, user) { console.log(user); }); }); @@ -418,13 +416,13 @@ request( console.log('server encoded the data as: ' + (response.headers['content-encoding'] || 'identity')) console.log('the decoded data is: ' + body) } - ).on('data', function(data) { + ).on('data', function(data: any) { // decompressed data as it is received console.log('decoded chunk: ' + data) }) - .on('response', function(response) { + .on('response', function(response: http.IncomingMessage) { // unmodified http.IncomingMessage object - response.on('data', function(data) { + response.on('data', function(data: any[]) { // compressed data as it is received console.log('received ' + data.length + ' bytes of compressed data') }) diff --git a/request/request-tests.ts b/request/request-tests.ts index 99c7f566c..2e878893b 100644 --- a/request/request-tests.ts +++ b/request/request-tests.ts @@ -212,7 +212,7 @@ request.get('http://google.com/img.png').pipe(request.put('http://mysite.com/img request .get('http://google.com/img.png') - .on('response', function(response) { + .on('response', function(response: any) { console.log(response.statusCode); // 200 console.log(response.headers['content-type']); // 'image/png' }) @@ -220,7 +220,7 @@ request request .get('http://mysite.com/doodle.png') - .on('error', function(err) { + .on('error', function(err: any) { console.log(err); }) .pipe(fs.createWriteStream('doodle.png')); @@ -370,7 +370,7 @@ options = { } }; -function callback(error, response, body) { +function callback(error: any, response: http.IncomingMessage, body: string) { if (!error && response.statusCode == 200) { var info = JSON.parse(body); console.log(info.stargazers_count + " Stars"); @@ -406,7 +406,7 @@ request.post({url:url, oauth:oauth}, function (e, r, body) { // step 3 // after the user is redirected back to your server - var auth_data = qs.parse(body) + var auth_data: any = qs.parse(body) , oauth = { consumer_key: CONSUMER_KEY , consumer_secret: CONSUMER_SECRET @@ -418,20 +418,19 @@ request.post({url:url, oauth:oauth}, function (e, r, body) { ; request.post({url:url, oauth:oauth}, function (e, r, body) { // ready to make signed requests on behalf of the user - var perm_data = qs.parse(body) - , oauth = + var perm_data: any = qs.parse(body); + var oauth = { consumer_key: CONSUMER_KEY , consumer_secret: CONSUMER_SECRET , token: perm_data.oauth_token , token_secret: perm_data.oauth_token_secret - } - , url = 'https://api.twitter.com/1.1/users/show.json' - , qs = - { screen_name: perm_data.screen_name - , user_id: perm_data.user_id - } - ; - request.get({url:url, oauth:oauth, qs:qs, json:true}, function (e, r, user) { + }; + var url = 'https://api.twitter.com/1.1/users/show.json'; + var query = { + screen_name: perm_data.screen_name, + user_id: perm_data.user_id + }; + request.get({url:url, oauth:oauth, qs:query, json:true}, function (e, r, user) { console.log(user); }); }); @@ -576,13 +575,13 @@ request( console.log('server encoded the data as: ' + (response.headers['content-encoding'] || 'identity')) console.log('the decoded data is: ' + body) } - ).on('data', function(data) { + ).on('data', function(data: any) { // decompressed data as it is received console.log('decoded chunk: ' + data) }) - .on('response', function(response) { + .on('response', function(response: http.IncomingMessage) { // unmodified http.IncomingMessage object - response.on('data', function(data) { + response.on('data', function(data: any[]) { // compressed data as it is received console.log('received ' + data.length + ' bytes of compressed data') }) diff --git a/request/request.d.ts b/request/request.d.ts index 202adf955..711b3d3c1 100644 --- a/request/request.d.ts +++ b/request/request.d.ts @@ -18,36 +18,33 @@ declare module 'request' { namespace request { export interface RequestAPI { defaults(options: Options): RequestAPI; - (uri: string, - options?: Options, - callback?: (error: any, response: http.IncomingMessage, body: any) => void) - : TRequest; - (uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; - (options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; + (uri: string, options?: Options, callback?: RequestCallback): TRequest; + (uri: string, callback?: RequestCallback): TRequest; + (options?: Options, callback?: RequestCallback): TRequest; - get(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; - get(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; - get(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; + get(uri: string, options?: Options, callback?: RequestCallback): TRequest; + get(uri: string, callback?: RequestCallback): TRequest; + get(options: Options, callback?: RequestCallback): TRequest; - post(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; - post(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; - post(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; + post(uri: string, options?: Options, callback?: RequestCallback): TRequest; + post(uri: string, callback?: RequestCallback): TRequest; + post(options: Options, callback?: RequestCallback): TRequest; - put(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; - put(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; - put(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; + put(uri: string, options?: Options, callback?: RequestCallback): TRequest; + put(uri: string, callback?: RequestCallback): TRequest; + put(options: Options, callback?: RequestCallback): TRequest; - head(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; - head(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; - head(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; + head(uri: string, options?: Options, callback?: RequestCallback): TRequest; + head(uri: string, callback?: RequestCallback): TRequest; + head(options: Options, callback?: RequestCallback): TRequest; - patch(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; - patch(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; - patch(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; + patch(uri: string, options?: Options, callback?: RequestCallback): TRequest; + patch(uri: string, callback?: RequestCallback): TRequest; + patch(options: Options, callback?: RequestCallback): TRequest; - del(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; - del(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; - del(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): TRequest; + del(uri: string, options?: Options, callback?: RequestCallback): TRequest; + del(uri: string, callback?: RequestCallback): TRequest; + del(options: Options, callback?: RequestCallback): TRequest; forever(agentOptions: any, optionsArg: any): TRequest; jar(): CookieJar; @@ -97,6 +94,10 @@ declare module 'request' { har?: HttpArchiveRequest; } + export interface RequestCallback { + (error: any, response: http.IncomingMessage, body: any): void; + } + export interface HttpArchiveRequest { url?: string; method?: string; From 98184ee41d3848d537e04d0414323e73cb2dbe47 Mon Sep 17 00:00:00 2001 From: Joe Skeen Date: Wed, 7 Oct 2015 10:51:29 -0600 Subject: [PATCH 06/69] Added back missing options and fixed promise exposure --- request-promise/request-promise.d.ts | 14 ++++++++++++-- request/request.d.ts | 6 +++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/request-promise/request-promise.d.ts b/request-promise/request-promise.d.ts index 67b82ebd8..7a94ce596 100644 --- a/request-promise/request-promise.d.ts +++ b/request-promise/request-promise.d.ts @@ -12,9 +12,19 @@ declare module 'request-promise' { import request = require('request'); import http = require('http'); - interface RequestPromise extends request.Request, Promise { + interface RequestPromise extends request.Request { + then(onFulfilled: Function, onRejected: Function): Promise; + catch(onRejected: Function): Promise; + finally(onFinished: Function): Promise; + promise(): Promise; } - var requestPromise: request.RequestAPI; + interface RequestPromiseOptions extends request.Options { + simple?: boolean; + transform?: (body: any, response: http.IncomingMessage) => any; + resolveWithFullResponse?: boolean; + } + + var requestPromise: request.RequestAPI; export = requestPromise; } diff --git a/request/request.d.ts b/request/request.d.ts index 711b3d3c1..f0ec40f3b 100644 --- a/request/request.d.ts +++ b/request/request.d.ts @@ -16,8 +16,8 @@ declare module 'request' { import fs = require('fs'); namespace request { - export interface RequestAPI { - defaults(options: Options): RequestAPI; + export interface RequestAPI { + defaults(options: Options): RequestAPI; (uri: string, options?: Options, callback?: RequestCallback): TRequest; (uri: string, callback?: RequestCallback): TRequest; (options?: Options, callback?: RequestCallback): TRequest; @@ -214,6 +214,6 @@ declare module 'request' { toString(): string; } } - var request: request.RequestAPI; + var request: request.RequestAPI; export = request; } From 1a9a1665fb7f72239ca3e3b0b5024ff7c0963c36 Mon Sep 17 00:00:00 2001 From: Joe Skeen Date: Wed, 7 Oct 2015 10:55:24 -0600 Subject: [PATCH 07/69] fix tests --- request-promise/request-promise.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/request-promise/request-promise.d.ts b/request-promise/request-promise.d.ts index 7a94ce596..1832787be 100644 --- a/request-promise/request-promise.d.ts +++ b/request-promise/request-promise.d.ts @@ -13,7 +13,7 @@ declare module 'request-promise' { import http = require('http'); interface RequestPromise extends request.Request { - then(onFulfilled: Function, onRejected: Function): Promise; + then(onFulfilled: Function, onRejected?: Function): Promise; catch(onRejected: Function): Promise; finally(onFinished: Function): Promise; promise(): Promise; From 6c9b4cf0248de82bc63dee6af72fe8dfb9d2501b Mon Sep 17 00:00:00 2001 From: Joe Skeen Date: Wed, 7 Oct 2015 10:58:20 -0600 Subject: [PATCH 08/69] fix implicit any --- request-promise/request-promise-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/request-promise/request-promise-tests.ts b/request-promise/request-promise-tests.ts index a4d28a8f4..347cca818 100644 --- a/request-promise/request-promise-tests.ts +++ b/request-promise/request-promise-tests.ts @@ -27,7 +27,7 @@ options = { }; rp(options) - .then(function (response) { + .then(function (response: http.IncomingMessage) { console.log("DELETE succeeded with status %d", response.statusCode); }) .catch(console.error); From 2d23048aa0c96acfa7d2c667484029acdd446896 Mon Sep 17 00:00:00 2001 From: Joe Skeen Date: Wed, 7 Oct 2015 11:12:48 -0600 Subject: [PATCH 09/69] Use generic Options to allow for custom options from request-promise --- request/request.d.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/request/request.d.ts b/request/request.d.ts index f0ec40f3b..db8ca8c7d 100644 --- a/request/request.d.ts +++ b/request/request.d.ts @@ -17,34 +17,34 @@ declare module 'request' { namespace request { export interface RequestAPI { - defaults(options: Options): RequestAPI; - (uri: string, options?: Options, callback?: RequestCallback): TRequest; + defaults(options: TOptions): RequestAPI; + (uri: string, options?: TOptions, callback?: RequestCallback): TRequest; (uri: string, callback?: RequestCallback): TRequest; - (options?: Options, callback?: RequestCallback): TRequest; + (options?: TOptions, callback?: RequestCallback): TRequest; - get(uri: string, options?: Options, callback?: RequestCallback): TRequest; + get(uri: string, options?: TOptions, callback?: RequestCallback): TRequest; get(uri: string, callback?: RequestCallback): TRequest; - get(options: Options, callback?: RequestCallback): TRequest; + get(options: TOptions, callback?: RequestCallback): TRequest; - post(uri: string, options?: Options, callback?: RequestCallback): TRequest; + post(uri: string, options?: TOptions, callback?: RequestCallback): TRequest; post(uri: string, callback?: RequestCallback): TRequest; - post(options: Options, callback?: RequestCallback): TRequest; + post(options: TOptions, callback?: RequestCallback): TRequest; - put(uri: string, options?: Options, callback?: RequestCallback): TRequest; + put(uri: string, options?: TOptions, callback?: RequestCallback): TRequest; put(uri: string, callback?: RequestCallback): TRequest; - put(options: Options, callback?: RequestCallback): TRequest; + put(options: TOptions, callback?: RequestCallback): TRequest; - head(uri: string, options?: Options, callback?: RequestCallback): TRequest; + head(uri: string, options?: TOptions, callback?: RequestCallback): TRequest; head(uri: string, callback?: RequestCallback): TRequest; - head(options: Options, callback?: RequestCallback): TRequest; + head(options: TOptions, callback?: RequestCallback): TRequest; - patch(uri: string, options?: Options, callback?: RequestCallback): TRequest; + patch(uri: string, options?: TOptions, callback?: RequestCallback): TRequest; patch(uri: string, callback?: RequestCallback): TRequest; - patch(options: Options, callback?: RequestCallback): TRequest; + patch(options: TOptions, callback?: RequestCallback): TRequest; - del(uri: string, options?: Options, callback?: RequestCallback): TRequest; + del(uri: string, options?: TOptions, callback?: RequestCallback): TRequest; del(uri: string, callback?: RequestCallback): TRequest; - del(options: Options, callback?: RequestCallback): TRequest; + del(options: TOptions, callback?: RequestCallback): TRequest; forever(agentOptions: any, optionsArg: any): TRequest; jar(): CookieJar; From 71b6e0f1fdbc2d43e0e2423505932a14b14081f1 Mon Sep 17 00:00:00 2001 From: ashwin027 Date: Wed, 7 Oct 2015 18:47:15 -0700 Subject: [PATCH 10/69] Added missing options to IGridoptions Added missing options enableGridMenu and useExternalFiltering. --- ui-grid/ui-grid.d.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ui-grid/ui-grid.d.ts b/ui-grid/ui-grid.d.ts index ece964280..47a2452f8 100644 --- a/ui-grid/ui-grid.d.ts +++ b/ui-grid/ui-grid.d.ts @@ -600,6 +600,13 @@ declare module uiGrid { * @default false */ enableFiltering?: boolean; + /** + * False by default. When enabled, this adds a settings icon in the top right of the grid, + * which floats above the column header. The menu by default gives access to show/hide columns, + * but can be customized to show additional actions. + * @default false + */ + enableGridMenu?: boolean; /** * uiGridConstants.scrollbars.ALWAYS by default. This settings controls the horizontal scrollbar for the grid. * Supported values: uiGridConstants.scrollbars.ALWAYS, uiGridConstants.scrollbars.NEVER @@ -791,6 +798,12 @@ declare module uiGrid { * @default 20 */ virtualizationThreshold?: number; + /** + * Disables client side filtering. When true, handle the filterChanged event and set data, + * defaults to false + * @default false + */ + useExternalFiltering?: boolean; /** * Default time in milliseconds to throttle scroll events to, defaults to 70ms * @default 70 From 7652e924ff0971f817916b8dd8823b085073e1a2 Mon Sep 17 00:00:00 2001 From: vpham6 Date: Wed, 21 Oct 2015 11:45:23 -0700 Subject: [PATCH 11/69] Update type for ngModelAttrs with key String --- angular-formly/angular-formly.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/angular-formly/angular-formly.d.ts b/angular-formly/angular-formly.d.ts index 8f76b3ccf..9917d217f 100644 --- a/angular-formly/angular-formly.d.ts +++ b/angular-formly/angular-formly.d.ts @@ -297,6 +297,7 @@ declare module AngularFormly { bound?: any; expression?: any; value?: any; + [key: string]: any; }; From 8864681db077703f359e779c1d65135d25edbccb Mon Sep 17 00:00:00 2001 From: MatejQ Date: Fri, 23 Oct 2015 15:34:53 +0200 Subject: [PATCH 12/69] Fixed CellClassGetter interfaces according to ui-grid JS code --- ui-grid/ui-grid.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui-grid/ui-grid.d.ts b/ui-grid/ui-grid.d.ts index ef013fdf1..bcf6efe7e 100644 --- a/ui-grid/ui-grid.d.ts +++ b/ui-grid/ui-grid.d.ts @@ -3752,7 +3752,7 @@ declare module uiGrid { } export interface ICellClassGetter { - (gridRow?: IGridRowOf, gridCol?: IGridColumnOf, colRenderIndex?: number): string; + (grid?: IGridInstanceOf, gridRow?: IGridRowOf, gridCol?: IGridColumnOf, rowRenderIndex?: number, colRenderIndex?: number): string; } export interface ICellTooltipGetter { @@ -3762,7 +3762,7 @@ declare module uiGrid { (gridCol: IGridColumnOf): string; } export interface IHeaderFooterCellClassGetter { - (gridRow: IGridRowOf, rowRenderIndex: number, gridCol: IGridColumnOf, colRenderIndex: number) + (grid: IGridInstanceOf, gridRow: IGridRowOf, gridCol: IGridColumnOf, rowRenderIndex: number, colRenderIndex: number) : string; } export interface IMenuItem { From 19e1e0847b972660738b2720a0bca867ffd399c1 Mon Sep 17 00:00:00 2001 From: MatejQ Date: Fri, 23 Oct 2015 15:56:04 +0200 Subject: [PATCH 13/69] Attempt to fix failing tests. --- ui-grid/ui-grid-tests.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ui-grid/ui-grid-tests.ts b/ui-grid/ui-grid-tests.ts index 95c81298a..fe88fec4f 100644 --- a/ui-grid/ui-grid-tests.ts +++ b/ui-grid/ui-grid-tests.ts @@ -12,9 +12,9 @@ columnDef.aggregationHideLabel = false; columnDef.aggregationType = 1; columnDef.aggregationType = function () { return 1; }; columnDef.cellClass = 'test'; -columnDef.cellClass = (gridRow, gridCol, index) => { - //types of gridRow, gridCol, and index are flowed in correctly - return `${gridRow.entity.name}-${gridCol.field}-${index + 1}`; +columnDef.cellClass = (grid, gridRow, gridCol, rowIndex, colIndex) => { + //types of grid, gridRow, gridCol, rowIndex and colIndex are flowed in correctly + return `${grid.footerHeight}-${gridRow.entity.name}-${gridCol.field}-${rowIndex + 1}-${colIndex + 1}`; }; columnDef.cellFilter = 'date'; columnDef.cellTemplate = '
hello
'; @@ -44,17 +44,17 @@ columnDef.filter = { columnDef.filterCellFiltered = false; columnDef.filterHeaderTemplate = '
'; columnDef.filters = [columnDef.filter]; -columnDef.footerCellClass = (gridRow, rowRenderIndex, gridCol, colRenderIndex) => { - //types for gridRow, rowRenderIndex, gridCol, and colRenderIndex flow in properly - return `${gridRow.entity.age}-${rowRenderIndex + 1}-${gridCol.field}-${colRenderIndex - 1}`; +columnDef.footerCellClass = (grid, gridRow, gridCol, rowRenderIndex, colRenderIndex) => { + //types for grid, gridRow, gridCol, rowRenderIndex, and colRenderIndex flow in properly + return `${grid.footerHeight}-${gridRow.entity.age}-${rowRenderIndex + 1}-${gridCol.field}-${colRenderIndex - 1}`; }; columnDef.footerCellClass = 'theClass'; columnDef.footerCellFilter = 'currency:$'; columnDef.footerCellTemplate = '
'; columnDef.headerCellClass = - (gridRow, rowRenderIndex, gridCol, colRenderIndex) => { - //types for gridRow, rowRenderIndex, gridCol, and colRenderIndex flow in properly - return `${gridRow.entity.age}-${rowRenderIndex + 1}-${gridCol.field}-${colRenderIndex - 1}`; + (grid, gridRow, gridCol, rowRenderIndex, colRenderIndex) => { + //types for grid, gridRow, gridCol, rowRenderIndex, and colRenderIndex flow in properly + return `${grid.footerHeight}-${gridRow.entity.age}-${rowRenderIndex + 1}-${gridCol.field}-${colRenderIndex - 1}`; }; columnDef.headerCellClass = 'classy'; columnDef.headerCellFilter = 'currency:$'; From 1d7d9e514e1978b74979cdfbc29a0b2ea8337cfc Mon Sep 17 00:00:00 2001 From: Jacob Eggers Date: Wed, 28 Oct 2015 00:05:07 -0700 Subject: [PATCH 14/69] Fixes #6489 --- request-promise/request-promise.d.ts | 3 ++- request/request.d.ts | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/request-promise/request-promise.d.ts b/request-promise/request-promise.d.ts index 246f1e5d9..1bc357dd1 100644 --- a/request-promise/request-promise.d.ts +++ b/request-promise/request-promise.d.ts @@ -22,10 +22,11 @@ declare module 'request-promise' { function RequestPromiseAPI(uri: string): Promise; module RequestPromiseAPI { - export interface Options extends request.Options { + interface AdditionalOptions { simple?: boolean; transform?: (body: any, response: http.IncomingMessage) => any; resolveWithFullResponse?: boolean; } + export type Options = AdditionalOptions & request.Options; } } diff --git a/request/request.d.ts b/request/request.d.ts index d3bbd5704..49c41f8fc 100644 --- a/request/request.d.ts +++ b/request/request.d.ts @@ -57,9 +57,15 @@ declare module 'request' { export var initParams: any; - export interface Options { - url?: string; - uri?: string; + interface UriOptions { + uri: string; + } + + interface UrlOptions { + url: string; + } + + interface OptionalOptions { callback?: (error: any, response: http.IncomingMessage, body: any) => void; jar?: any; // CookieJar formData?: any; // Object @@ -90,6 +96,8 @@ declare module 'request' { gzip?: boolean; } + export type Options = (UriOptions|UrlOptions)&OptionalOptions; + export interface RequestPart { headers?: Headers; body: any; From f58cfb989f00ec880d4b4acad0f52bc5bf7aba0b Mon Sep 17 00:00:00 2001 From: Zhiyuan Wang Date: Wed, 28 Oct 2015 15:20:34 +0800 Subject: [PATCH 15/69] add definition and test for merge-descriptor --- merge-descriptors/merge-descriptors-tests.ts | 35 +++++++++++++++++++ .../merge-descriptors-tests.ts.tscparams | 1 + merge-descriptors/merge-descriptors.d.ts | 13 +++++++ 3 files changed, 49 insertions(+) create mode 100644 merge-descriptors/merge-descriptors-tests.ts create mode 100644 merge-descriptors/merge-descriptors-tests.ts.tscparams create mode 100644 merge-descriptors/merge-descriptors.d.ts diff --git a/merge-descriptors/merge-descriptors-tests.ts b/merge-descriptors/merge-descriptors-tests.ts new file mode 100644 index 000000000..81376320f --- /dev/null +++ b/merge-descriptors/merge-descriptors-tests.ts @@ -0,0 +1,35 @@ +/// +import mixin = require('merge-descriptors'); + +function testAssertion(condition: boolean, errorMessage: string) { + if (!condition) { + throw new Error(errorMessage); + } +} + +interface IMergedObject { + InSrc?: string; + name: string; + InTarget: string; +} + +var src = { + InSrc: 'src', + get name(): string { + return 'from src name'; + } +} + +var target: IMergedObject = { name: 'my target name', InTarget: 'target' }; + +var target2 = mixin(target, src, true); + +console.log(JSON.stringify(target)); + +testAssertion(target2 === target, "Returned object should refer to input [destination] object"); +testAssertion(target.name === 'from src name', "[redfine]=true, source member will overwrite destination member"); +testAssertion(target.InTarget === 'target', "overwrite do not affect members only in [destination]"); +testAssertion(target['InSrc'] === 'src', "members from [source] must be copied to [destination]"); + +var nameProperty:PropertyDescriptor = Object.getOwnPropertyDescriptor(target, "name"); +testAssertion(nameProperty.set === undefined, "member descriptor must be overwritten"); \ No newline at end of file diff --git a/merge-descriptors/merge-descriptors-tests.ts.tscparams b/merge-descriptors/merge-descriptors-tests.ts.tscparams new file mode 100644 index 000000000..4169d3605 --- /dev/null +++ b/merge-descriptors/merge-descriptors-tests.ts.tscparams @@ -0,0 +1 @@ +--noImplicitAny --module commonjs --target es5 \ No newline at end of file diff --git a/merge-descriptors/merge-descriptors.d.ts b/merge-descriptors/merge-descriptors.d.ts new file mode 100644 index 000000000..8e3212edd --- /dev/null +++ b/merge-descriptors/merge-descriptors.d.ts @@ -0,0 +1,13 @@ +// Type definitions for merge-descriptors +// Project: https://github.com/component/merge-descriptors +// Definitions by: Zhiyuan Wang +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module 'merge-descriptors' { + + function merge(destination: Object, source: Object): Object; + + function merge(destination: Object, source: Object, redefine: boolean): Object; + + export = merge; +} \ No newline at end of file From d42c7e25f743c928986821fa555015bce87e2ba1 Mon Sep 17 00:00:00 2001 From: John Alfaro Date: Wed, 28 Oct 2015 13:58:48 -0400 Subject: [PATCH 16/69] #6487 - gridfs-stream.d.ts - Support for findOne and curCol Added declarat --- gridfs-stream/gridfs-stream.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gridfs-stream/gridfs-stream.d.ts b/gridfs-stream/gridfs-stream.d.ts index a8ad5f9ed..7dc355daf 100644 --- a/gridfs-stream/gridfs-stream.d.ts +++ b/gridfs-stream/gridfs-stream.d.ts @@ -52,6 +52,7 @@ declare module "gridfs-stream" { files: mongo.Collection; collection(name?: string): mongo.Collection; + curCol: string; createWriteStream(options?: GridFSStream.Options): GridFSStream.WriteStream; createReadStream(options?: GridFSStream.Options): GridFSStream.ReadStream; @@ -60,6 +61,7 @@ declare module "gridfs-stream" { remove(options: GridFSStream.Options, callback: (err: Error) => void): void; exist(options: GridFSStream.Options, callback: (err: Error, found: boolean) => void): void; + findOne(options: GridFSStream.Options, callback: (err: Error, record: any)=>void):void; } } From 3637fe5a062c4a1ab987a22960c4c12f61296ef0 Mon Sep 17 00:00:00 2001 From: Kapil Sachdeva Date: Wed, 28 Oct 2015 19:01:23 -0500 Subject: [PATCH 17/69] Add the ngCordova type definitions This changeset add the bindings for $cordovaDevice & $cordovaToast services --- ngCordova/device-tests.ts | 42 +++++++++++++++++++++ ngCordova/device.d.ts | 77 +++++++++++++++++++++++++++++++++++++++ ngCordova/toast-tests.ts | 51 ++++++++++++++++++++++++++ ngCordova/toast.d.ts | 21 +++++++++++ ngCordova/tsd.d.ts | 2 + 5 files changed, 193 insertions(+) create mode 100644 ngCordova/device-tests.ts create mode 100644 ngCordova/device.d.ts create mode 100644 ngCordova/toast-tests.ts create mode 100644 ngCordova/toast.d.ts create mode 100644 ngCordova/tsd.d.ts diff --git a/ngCordova/device-tests.ts b/ngCordova/device-tests.ts new file mode 100644 index 000000000..c5f761326 --- /dev/null +++ b/ngCordova/device-tests.ts @@ -0,0 +1,42 @@ +/// +/// +/// + +// For the full application demo please see follow repo : +// https://github.com/ksachdeva/ngCordova-typescript-demo + +namespace demo.device { + 'use strict'; + + interface IDeviceViewModel { + available:boolean; + cordova:string; + model:string; + platform:string; + uuid:string; + version:string; + } + + export class DeviceController { + + public vm:IDeviceViewModel; + + static $inject:Array = ["$ionicPlatform", "$cordovaDevice"]; + constructor($ionicPlatform:ionic.platform.IonicPlatformService, $cordovaDevice:ngCordova.IDeviceService) { + + $ionicPlatform.ready(() => { + this.vm = { + available : $cordovaDevice.getDevice().available, + cordova : $cordovaDevice.getCordova(), + model : $cordovaDevice.getModel(), + platform : $cordovaDevice.getPlatform(), + uuid : $cordovaDevice.getUUID(), + version : $cordovaDevice.getVersion() + }; + }); + } + + } + + angular.module("demo.device").controller("DeviceController", DeviceController); +} \ No newline at end of file diff --git a/ngCordova/device.d.ts b/ngCordova/device.d.ts new file mode 100644 index 000000000..760b37cef --- /dev/null +++ b/ngCordova/device.d.ts @@ -0,0 +1,77 @@ +// Type definitions for ngCordova device plugin +// Project: https://github.com/driftyco/ng-cordova +// Definitions by: Kapil Sachdeva + +declare module ngCordova { + + interface IDeviceInfo { + available:boolean; + platform:string; + version:string; + uuid:string; + cordova:string; + model:string; + manufacturer:string; + isVirtual:boolean; + serial:string; + } + + interface IDeviceService { + + /** + * Returns the whole device object. + * @see https://github.com/apache/cordova-plugin-device + * @returns {Object} The device object. + */ + getDevice():IDeviceInfo; + + /** + * Returns the Cordova version. + * @see https://github.com/apache/cordova-plugin-device#devicecordova + * @returns {String} The Cordova version. + */ + getCordova():string; + + /** + * Returns the name of the device's model or product. + * @see https://github.com/apache/cordova-plugin-device#devicemodel + * @returns {String} The name of the device's model or product. + */ + getModel():string; + + + /** + * @deprecated device.name is deprecated as of version 2.3.0. Use device.model instead. + * @returns {String} + */ + getName():string; + + /** + * Returns the device's operating system name. + * @see https://github.com/apache/cordova-plugin-device#deviceplatform + * @returns {String} The device's operating system name. + */ + getPlatform():string; + + + /** + * Returns the device's Universally Unique Identifier. + * @see https://github.com/apache/cordova-plugin-device#deviceuuid + * @returns {String} The device's Universally Unique Identifier + */ + getUUID():string; + + /** + * Returns the operating system version. + * @see https://github.com/apache/cordova-plugin-device#deviceversion + * @returns {String} + */ + getVersion():string; + + /** + * Returns the device manufacturer. + * @returns {String} + */ + getManufacturer():string; + } +} \ No newline at end of file diff --git a/ngCordova/toast-tests.ts b/ngCordova/toast-tests.ts new file mode 100644 index 000000000..1d067a92b --- /dev/null +++ b/ngCordova/toast-tests.ts @@ -0,0 +1,51 @@ +/// +/// +/// + +// For the full application demo please see follow repo : +// https://github.com/ksachdeva/ngCordova-typescript-demo + +namespace demo.toast { + 'use strict'; + + export class ToastController { + + toastMessage:string = 'enter a message'; + msg:string; + + static $inject:Array = ["$cordovaToast"]; + constructor(private $cordovaToast:ngCordova.IToastService) { + + } + + center() { + this.$cordovaToast.show(this.toastMessage, 'long', 'center') + .then((success) => { + console.log("center msg displayed"); + }, (error) => { + this.msg = error.message; + }); + } + + top() { + this.$cordovaToast.showShortTop(this.toastMessage) + .then((success) => { + console.log("short top msg displayed"); + }, (error) => { + this.msg = error.message; + }); + } + + bottom() { + this.$cordovaToast.showLongBottom(this.toastMessage) + .then((success) => { + console.log("long bottom msg displayed"); + }, (error) => { + this.msg = error.message; + }); + } + + } + + angular.module("demo.toast").controller("ToastController", ToastController); +} \ No newline at end of file diff --git a/ngCordova/toast.d.ts b/ngCordova/toast.d.ts new file mode 100644 index 000000000..c7dd6a980 --- /dev/null +++ b/ngCordova/toast.d.ts @@ -0,0 +1,21 @@ +// Type definitions for ngCordova toast plugin +// Project: https://github.com/driftyco/ng-cordova +// Definitions by: Kapil Sachdeva + +/// + +declare module ngCordova { + + interface IToastService { + + showShortTop(message:string):angular.IPromise; + showShortCenter(message:string):angular.IPromise; + showShortBottom(message:string):angular.IPromise; + + showLongTop(message:string):angular.IPromise; + showLongCenter(message:string):angular.IPromise; + showLongBottom(message:string):angular.IPromise; + + show(message:string, duration:string, position:string):angular.IPromise; + } +} \ No newline at end of file diff --git a/ngCordova/tsd.d.ts b/ngCordova/tsd.d.ts new file mode 100644 index 000000000..13cbd0f26 --- /dev/null +++ b/ngCordova/tsd.d.ts @@ -0,0 +1,2 @@ +/// +/// From ac7ddea017ca3e61975da263c29f9e20cbe6af8c Mon Sep 17 00:00:00 2001 From: Kapil Sachdeva Date: Wed, 28 Oct 2015 19:09:33 -0500 Subject: [PATCH 18/69] Corrections for the conventions for the file headers --- ngCordova/device-tests.ts | 2 +- ngCordova/device.d.ts | 3 ++- ngCordova/toast-tests.ts | 2 +- ngCordova/toast.d.ts | 3 ++- ngCordova/tsd.d.ts | 5 +++++ 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ngCordova/device-tests.ts b/ngCordova/device-tests.ts index c5f761326..37a30bf66 100644 --- a/ngCordova/device-tests.ts +++ b/ngCordova/device-tests.ts @@ -2,7 +2,7 @@ /// /// -// For the full application demo please see follow repo : +// For the full application demo please see following repo : // https://github.com/ksachdeva/ngCordova-typescript-demo namespace demo.device { diff --git a/ngCordova/device.d.ts b/ngCordova/device.d.ts index 760b37cef..8171fb3fc 100644 --- a/ngCordova/device.d.ts +++ b/ngCordova/device.d.ts @@ -1,6 +1,7 @@ // Type definitions for ngCordova device plugin // Project: https://github.com/driftyco/ng-cordova -// Definitions by: Kapil Sachdeva +// Definitions by: Kapil Sachdeva +// Definitions: https://github.com/ksachdeva/DefinitelyTyped declare module ngCordova { diff --git a/ngCordova/toast-tests.ts b/ngCordova/toast-tests.ts index 1d067a92b..43ed529e5 100644 --- a/ngCordova/toast-tests.ts +++ b/ngCordova/toast-tests.ts @@ -2,7 +2,7 @@ /// /// -// For the full application demo please see follow repo : +// For the full application demo please see following repo : // https://github.com/ksachdeva/ngCordova-typescript-demo namespace demo.toast { diff --git a/ngCordova/toast.d.ts b/ngCordova/toast.d.ts index c7dd6a980..8e5c6ba0c 100644 --- a/ngCordova/toast.d.ts +++ b/ngCordova/toast.d.ts @@ -1,6 +1,7 @@ // Type definitions for ngCordova toast plugin // Project: https://github.com/driftyco/ng-cordova -// Definitions by: Kapil Sachdeva +// Definitions by: Kapil Sachdeva +// Definitions: https://github.com/ksachdeva/DefinitelyTyped /// diff --git a/ngCordova/tsd.d.ts b/ngCordova/tsd.d.ts index 13cbd0f26..726ea99e6 100644 --- a/ngCordova/tsd.d.ts +++ b/ngCordova/tsd.d.ts @@ -1,2 +1,7 @@ +// Type definitions for ngCordova plugins +// Project: https://github.com/driftyco/ng-cordova +// Definitions by: Kapil Sachdeva +// Definitions: https://github.com/ksachdeva/DefinitelyTyped + /// /// From ee5dffce66ae102783f3c23cfc836696110fdf62 Mon Sep 17 00:00:00 2001 From: Zhiyuan Wang Date: Fri, 30 Oct 2015 08:28:47 +0800 Subject: [PATCH 19/69] Add definitions and tests for NodeJs package [depd] --- depd/depd-tests.ts | 54 ++++++++++++++++++++++++++++++++++++++++++++++ depd/depd.d.ts | 17 +++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 depd/depd-tests.ts create mode 100644 depd/depd.d.ts diff --git a/depd/depd-tests.ts b/depd/depd-tests.ts new file mode 100644 index 000000000..14dfbe72c --- /dev/null +++ b/depd/depd-tests.ts @@ -0,0 +1,54 @@ +/// + +import depd = require('depd'); + +var deprecate = depd("depd-tests"); + +function assert(condition: boolean, message: string): void { + if (!condition) { + throw new Error(message); + } +} + +function testDepdMessage(...args: string[]): boolean { + if (arguments.length < 1) { + deprecate('testDepdMessage argument.lenth<1'); + return true; + } else { + console.log('normal logic'); + return false; + } +} + +assert(testDepdMessage() === true, "Deprecated code must be triggered!"); +assert(testDepdMessage('a') === false, "Deprecated code must be triggered!"); + +interface ITestObject { + p1: string; + p2: string; +} + +var obj = { p1: 'deprecated property', p2: 'normal property' }; +deprecate.property(obj, 'p1', 'property [p1] is deprecated!'); + +console.log(obj.p1); + +interface ITestDeprecatedFunction { + func1?: Function; + func2?: Function; +} + +var obj2 = {}; + +// message automatically derived from function name +obj2.func1 = deprecate.function(function func1() { + console.log('all calls to [func1] are deprecated '); +}); + +// specific message +obj2.func2 = deprecate.function(function () { + console.log('all calls to [func2] are deprecated '); +}, 'func2'); + +obj2.func1(); +obj2.func2(); \ No newline at end of file diff --git a/depd/depd.d.ts b/depd/depd.d.ts new file mode 100644 index 000000000..33f7b72a0 --- /dev/null +++ b/depd/depd.d.ts @@ -0,0 +1,17 @@ +// Type definitions for nodejs package depd 1.1.0 +// Project: https://github.com/dougwilson/nodejs-depd +// Definitions by: Zhiyuan Wang +// Definitions: https://github.com/borisyankov/DefinitelyTyped + + +declare module 'depd' { + function depd(namespace: string): Deprecate; + + interface Deprecate { + (message: string): void; + function(fn: Function, message?: string): Function; + property(obj: Object, prop: string, message: string): void; + } + + export = depd; +} \ No newline at end of file From cb16d9359e8bfd91dc92bcbb1a58a3964c21dd30 Mon Sep 17 00:00:00 2001 From: Zhiyuan Wang Date: Fri, 30 Oct 2015 08:39:23 +0800 Subject: [PATCH 20/69] adjust definition header since validation failure in PR --- depd/depd.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depd/depd.d.ts b/depd/depd.d.ts index 33f7b72a0..1af4eaa8d 100644 --- a/depd/depd.d.ts +++ b/depd/depd.d.ts @@ -1,4 +1,4 @@ -// Type definitions for nodejs package depd 1.1.0 +// Type definitions for depd 1.1.0 // Project: https://github.com/dougwilson/nodejs-depd // Definitions by: Zhiyuan Wang // Definitions: https://github.com/borisyankov/DefinitelyTyped From 147380f9d1255f779806270d80eea85e2c1af55f Mon Sep 17 00:00:00 2001 From: edvin Date: Fri, 30 Oct 2015 13:38:06 +0100 Subject: [PATCH 21/69] Support global sprintf and vsprintf for use in browser. --- sprintf-js/sprintf-js.d.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sprintf-js/sprintf-js.d.ts b/sprintf-js/sprintf-js.d.ts index fba1925b6..89377b83d 100644 --- a/sprintf-js/sprintf-js.d.ts +++ b/sprintf-js/sprintf-js.d.ts @@ -10,7 +10,7 @@ Its prototype is simple: string sprintf(string format , [mixed arg1 [, mixed arg2 [ ,...]]]) */ -declare module "sprintf-js" { +declare module sprintf_js { /** sprintf.js is a complete open source JavaScript sprintf implementation for the browser and node.js. Its prototype is simple: string sprintf(string format , [mixed arg1 [, mixed arg2 [ ,...]]]) @@ -69,3 +69,10 @@ X - yields an integer as a hexadecimal number (upper-case) */ export function vsprintf(fmt: string, args: any[]): string; } + +declare module "sprintf-js" { + export =sprintf_js; +} + +declare var sprintf: typeof sprintf_js.sprintf; +declare var vsprintf: typeof sprintf_js.vsprintf; From b1956785d638d352d4045bae2b35dca7c19b0b41 Mon Sep 17 00:00:00 2001 From: Zhiyuan Wang Date: Fri, 30 Oct 2015 21:24:22 +0800 Subject: [PATCH 22/69] Add definitions and tests for NodeJs package bytes v2.1.0 --- bytes/bytes-tests.ts | 16 +++++++++++ bytes/bytes.d.ts | 66 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 bytes/bytes-tests.ts create mode 100644 bytes/bytes.d.ts diff --git a/bytes/bytes-tests.ts b/bytes/bytes-tests.ts new file mode 100644 index 000000000..4a981aee4 --- /dev/null +++ b/bytes/bytes-tests.ts @@ -0,0 +1,16 @@ +/// + +import bytes = require('bytes'); + +// 1024*1024 = 1048576 +console.log(bytes(104857)); +console.log(bytes(104857, { thousandsSeparator: ' ' })); + +console.log(bytes.format(104857)); +console.log(bytes.format(104857, { thousandsSeparator: ' ' })); + +console.log(bytes('1024kb')); +console.log(bytes(1024)); + +console.log(bytes.parse('1024kb')); +console.log(bytes.parse(1024)); \ No newline at end of file diff --git a/bytes/bytes.d.ts b/bytes/bytes.d.ts new file mode 100644 index 000000000..d9946edf2 --- /dev/null +++ b/bytes/bytes.d.ts @@ -0,0 +1,66 @@ +// Type definitions for bytes v2.1.0 +// Project: https://github.com/visionmedia/bytes.js +// Definitions by: Zhiyuan Wang +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module 'bytes' { + + interface IBytesFormatOptions { + thousandsSeparator: string + } + + /** + *Convert the given value in bytes into a string. + * + * @param {number} value + * @param {{ + * thousandsSeparator: [string] + * }} [options] bytes options. + * + * @returns {string} + */ + function bytes(value: number, options?: IBytesFormatOptions): string; + + /** + *Parse string to an integer in bytes. + * + * @param {string} value + * @returns {number} + */ + function bytes(value: string): number; + + module bytes { + + /** + * Format the given value in bytes into a string. + * + * If the value is negative, take Math.abs(). If it is a float, + * it is rounded. + * + * @param {number} value + * @param {IBytesFormatOptions} [options] + */ + + function format(value: number, options?: IBytesFormatOptions): string; + + /** + * Just return the input number value. + * + * @param {number} value + * @return {number} + */ + function parse(value: number): number; + + /** + * Parse the string value into an integer in bytes. + * + * If no unit is given, it is assumed the value is in bytes. + * + * @param {string} value + * @return {number} + */ + function parse(value: string): number; + } + + export = bytes; +} \ No newline at end of file From 4331a333df4e8d47f3f221bbe797fc7dd989457b Mon Sep 17 00:00:00 2001 From: Zhiyuan Wang Date: Sat, 31 Oct 2015 20:04:55 +0800 Subject: [PATCH 23/69] add definitions and tests for NodeJs package ms v0.7.1 --- ms/ms-tests.ts | 14 ++++++++++++++ ms/ms.d.ts | 30 ++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 ms/ms-tests.ts create mode 100644 ms/ms.d.ts diff --git a/ms/ms-tests.ts b/ms/ms-tests.ts new file mode 100644 index 000000000..75312e927 --- /dev/null +++ b/ms/ms-tests.ts @@ -0,0 +1,14 @@ +/// + +import ms = require('ms'); + +ms('2 days') // 172800000 +ms('1d') // 86400000 + +ms(60000) // "1m" +ms(2 * 60000) // "2m" +ms(ms('10 hours')) // "10h" + +ms(60000, { long: true }) // "1 minute" +ms(2 * 60000, { long: true }) // "2 minutes" +ms(ms('10 hours'), { long: true }) // "10 hours" \ No newline at end of file diff --git a/ms/ms.d.ts b/ms/ms.d.ts new file mode 100644 index 000000000..5a7c67add --- /dev/null +++ b/ms/ms.d.ts @@ -0,0 +1,30 @@ +// Type definitions for ms v0.7.1 +// Project: https://github.com/guille/ms.js +// Definitions by: Zhiyuan Wang +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module 'ms' { + + interface IMSOptions { + long: boolean + } + + /** + * Short/Long format for `value`. + * + * @param {Number} value + * @param {{long: boolean}} options + * @return {String} + */ + function ms(value: number, options?: IMSOptions): string; + + /** + * Parse the given `value` and return milliseconds. + * + * @param {String} value + * @return {Number} + */ + function ms(value: string): number; + + export = ms; +} \ No newline at end of file From a809e347c94f642cdffae40c42b1ea45f84ad9ad Mon Sep 17 00:00:00 2001 From: floriantopf Date: Sun, 1 Nov 2015 01:22:54 +0100 Subject: [PATCH 24/69] react-onLoad-event --- react/react.d.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/react/react.d.ts b/react/react.d.ts index ba86c4690..25a3a30b9 100644 --- a/react/react.d.ts +++ b/react/react.d.ts @@ -313,6 +313,8 @@ declare namespace __React { deltaZ: number; } + interface LoadEvent extends SyntheticEvent {} + // // Event Handler Types // ---------------------------------------------------------------------- @@ -330,6 +332,7 @@ declare namespace __React { interface TouchEventHandler extends EventHandler {} interface UIEventHandler extends EventHandler {} interface WheelEventHandler extends EventHandler {} + interface LoadEventHandler extends EventHandler {} // // Props / DOM Attributes @@ -377,6 +380,7 @@ declare namespace __React { onTouchStart?: TouchEventHandler; onScroll?: UIEventHandler; onWheel?: WheelEventHandler; + onLoad?: LoadEventHandler; className?: string; id?: string; From 124f32ed3cc9c46b666232527a9d2a753d4c6b0f Mon Sep 17 00:00:00 2001 From: tkqubo Date: Sun, 1 Nov 2015 11:39:18 +0900 Subject: [PATCH 25/69] webpack: add HMR --- webpack/webpack-env-tests.ts | 27 +++++++ webpack/webpack-env.d.ts | 135 +++++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+) diff --git a/webpack/webpack-env-tests.ts b/webpack/webpack-env-tests.ts index b4a9693ec..25ec177d6 100644 --- a/webpack/webpack-env-tests.ts +++ b/webpack/webpack-env-tests.ts @@ -13,3 +13,30 @@ let contextModule = context('./someModule'); require(['./someModule', './otherModule'], (someModule: SomeModule, otherModule: any) => { }); + +// check if HMR is enabled +if(module.hot) { + // accept update of dependency + module.hot.accept("./handler.js", function() { + //... + }); +} + +module.exports = null; + +// check if HMR is enabled +if(module.hot) { + + // accept itself + module.hot.accept(); + + // dispose handler + module.hot.dispose(function() { + // revoke the side effect + //... + }); +} + + +var status: string = module.hot.status(); + diff --git a/webpack/webpack-env.d.ts b/webpack/webpack-env.d.ts index f67b9c5d6..07f160c5e 100644 --- a/webpack/webpack-env.d.ts +++ b/webpack/webpack-env.d.ts @@ -5,6 +5,7 @@ /** * Webpack module API - variables and global functions available inside modules + * https://webpack.github.io/docs/api-in-modules.html */ declare namespace __WebpackModuleApi { @@ -101,3 +102,137 @@ declare var __non_webpack_require__: any; * Equals the config option debug */ declare var DEBUG: boolean; + +/** + * Webpack Hot Module Replacement + * https://webpack.github.io/docs/hot-module-replacement.html + */ +declare namespace __WebpackHotModuleReplacement { + interface Module { + exports: any; + require(id: string): any; + id: string; + filename: string; + loaded: boolean; + parent: any; + children: any[]; + hot: Hot; + } + + interface Hot { + /** + * Accept code updates for the specified dependencies. The callback is called when dependencies were replaced. + * @param dependencies + * @param callback + */ + accept(dependencies: string[], callback: (updatedDependencies: string[]) => void): void; + /** + * Accept code updates for the specified dependencies. The callback is called when dependencies were replaced. + * @param dependency + * @param callback + */ + accept(dependency: string, callback: () => void): void; + /** + * Accept code updates for this module without notification of parents. + * This should only be used if the module doesn’t export anything. + * The errHandler can be used to handle errors that occur while loading the updated module. + * @param errHandler + */ + accept(errHandler?: Function): void; + /** + * Do not accept updates for the specified dependencies. If any dependencies is updated, the code update fails with code "decline". + */ + decline(dependencies: string[]): void; + /** + * Do not accept updates for the specified dependencies. If any dependencies is updated, the code update fails with code "decline". + */ + decline(dependency: string): void; + /** + * Flag the current module as not update-able. If updated the update code would fail with code "decline". + */ + decline(): void; + /** + * Add a one time handler, which is executed when the current module code is replaced. + * Here you should destroy/remove any persistent resource you have claimed/created. + * If you want to transfer state to the new module, add it to data object. + * The data will be available at module.hot.data on the new module. + * @param callback + */ + dispose(callback: (data: any) => void): void; + /** + * Add a one time handler, which is executed when the current module code is replaced. + * Here you should destroy/remove any persistent resource you have claimed/created. + * If you want to transfer state to the new module, add it to data object. + * The data will be available at module.hot.data on the new module. + * @param callback + */ + addDisposeHandler(callback: (data: any) => void): void; + /** + * Remove a handler. + * This can useful to add a temporary dispose handler. You could i. e. replace code while in the middle of a multi-step async function. + * @param callback + */ + removeDisposeHandler(callback: (data: any) => void): void; + /** + * Throws an exceptions if status() is not idle. + * Check all currently loaded modules for updates and apply updates if found. + * If no update was found, the callback is called with null. + * If autoApply is truthy the callback will be called with all modules that were disposed. + * apply() is automatically called with autoApply as options parameter. + * If autoApply is not set the callback will be called with all modules that will be disposed on apply(). + * @param autoApply + * @param callback + */ + check(autoApply: boolean, callback: (err: Error, outdatedModules: any[]) => void): void; + /** + * Throws an exceptions if status() is not idle. + * Check all currently loaded modules for updates and apply updates if found. + * If no update was found, the callback is called with null. + * The callback will be called with all modules that will be disposed on apply(). + * @param callback + */ + check(callback: (err: Error, outdatedModules: any[]) => void): void; + /** + * If status() != "ready" it throws an error. + * Continue the update process. + * @param options + * @param callback + */ + apply(options: AcceptOptions, callback: (err: Error, outdatedModules: any[]) => void): void; + /** + * If status() != "ready" it throws an error. + * Continue the update process. + * @param callback + */ + apply(callback: (err: Error, outdatedModules: any[]) => void): void; + /** + * Return one of idle, check, watch, watch-delay, prepare, ready, dispose, apply, abort or fail. + */ + status(): string; + /** Register a callback on status change. */ + status(callback: (status: string) => void): void; + /** Register a callback on status change. */ + addStatusHandler(callback: (status: string) => void): void; + /** + * Remove a registered status change handler. + * @param callback + */ + removeStatusHandler(callback: (status: string) => void): void; + + active: boolean; + data: any; + } + + interface AcceptOptions { + /** + * If true the update process continues even if some modules are not accepted (and would bubble to the entry point). + */ + ignoreUnaccepted: boolean; + /** + * Indicates that apply() is automatically called by check function + */ + autoApply: boolean; + } +} + +declare var module: __WebpackHotModuleReplacement.Module; From 19a046ce14527ae0922226655924660f3fa63255 Mon Sep 17 00:00:00 2001 From: Ali Taheri Date: Sun, 1 Nov 2015 11:09:06 +0330 Subject: [PATCH 26/69] [jest] improved typings. --- jest/jest-tests.ts | 2 +- jest/jest.d.ts | 59 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/jest/jest-tests.ts b/jest/jest-tests.ts index 764daf142..da141ef9e 100644 --- a/jest/jest-tests.ts +++ b/jest/jest-tests.ts @@ -47,7 +47,7 @@ describe('displayUser', function() { '