From 0dd5ad7c0f031515546c90aa1faf06054c46ce83 Mon Sep 17 00:00:00 2001 From: Marcin Porebski Date: Fri, 27 Nov 2015 13:44:42 +0100 Subject: [PATCH 1/3] Wreck 7.0.0 typings --- wreck/wreck-tests.ts | 41 ++++++++++++++++++++++++++++++++++++++++ wreck/wreck.d.ts | 45 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 wreck/wreck-tests.ts create mode 100644 wreck/wreck.d.ts diff --git a/wreck/wreck-tests.ts b/wreck/wreck-tests.ts new file mode 100644 index 000000000..b1e8b0d0b --- /dev/null +++ b/wreck/wreck-tests.ts @@ -0,0 +1,41 @@ +/// + +import Wreck = require('wreck'); + +Wreck.get('https://google.com/', function (err, res, payload) { + /* do stuff */ +}); + + +var method = 'GET'; // GET, POST, PUT, DELETE +var uri = 'https://google.com/'; +var readableStream = Wreck.toReadableStream('foo=bar'); + +var wreck = Wreck.defaults({ + headers: { 'x-foo-bar': 123 } +}); + +// cascading example -- does not alter `wreck` +var wreckWithTimeout = wreck.defaults({ + timeout: 5 +}); + +// all attributes are optional +var options = { + maxBytes: 1048576, // 1 MB, default: unlimited + rejectUnauthorized: true, + downstreamRes: null, + agent: null, // Node Core http.Agent +}; + +var optionalCallback = function (err, res) { + + /* handle err if it exists, in which case res will be undefined */ + + // buffer the response stream + Wreck.read(res, null, function (err, body) { + /* do stuff */ + }); +}; + +var req = wreck.request(method, uri, options, optionalCallback); diff --git a/wreck/wreck.d.ts b/wreck/wreck.d.ts new file mode 100644 index 000000000..7198de2bb --- /dev/null +++ b/wreck/wreck.d.ts @@ -0,0 +1,45 @@ +// Type definitions for wreck 7.0.0 +// Project: https://github.com/hapijs/wreck +// Definitions by: Marcin Porębski +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module Wreck +{ + import http = require('http'); + import stream = require('stream'); + + + interface IWreckObject + { + defaults: (options: any) => IWreckObject; + + request: (method: string, uri: string, options: any = null, callback: (err: any, response: http.IncomingMessage) => void = null) => http.ClientRequest; + + read: (response: http.IncomingMessage, options: any, callback: (err: any, payload: any) => void) => void; + + get: (uri: string, options: any = null, callback: (err: any, response: http.IncomingMessage, payload: any) => void = null) => http.ClientRequest; + post: (uri: string, options: any = null, callback: (err: any, response: http.IncomingMessage, payload: any) => void = null) => http.ClientRequest; + patch: (uri: string, options: any = null, callback: (err: any, response: http.IncomingMessage, payload: any) => void = null) => http.ClientRequest; + put: (uri: string, options: any = null, callback: (err: any, response: http.IncomingMessage, payload: any) => void = null) => http.ClientRequest; + delete: (uri: string, options: any = null, callback: (err: any, response: http.IncomingMessage, payload: any) => void = null) => http.ClientRequest; + + toReadableStream: (payload: any, encoding: string = null) => stream.Readable; + + parseCacheControl: (field: string) => any; + + agents: { + http: http.Agent, + https: http.Agent + }; + } + +} + +declare module "wreck" +{ + var wreck: Wreck.IWreckObject; + + export = wreck; +} From 117d429754f3f0a52ae903c3203e0a703022f488 Mon Sep 17 00:00:00 2001 From: Marcin Porebski Date: Fri, 27 Nov 2015 13:53:54 +0100 Subject: [PATCH 2/3] Wreck 7.0.0 typings - fixes --- wreck/wreck-tests.ts | 10 ++++------ wreck/wreck.d.ts | 22 +++++++++------------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/wreck/wreck-tests.ts b/wreck/wreck-tests.ts index b1e8b0d0b..6e7abab0e 100644 --- a/wreck/wreck-tests.ts +++ b/wreck/wreck-tests.ts @@ -2,7 +2,7 @@ import Wreck = require('wreck'); -Wreck.get('https://google.com/', function (err, res, payload) { +Wreck.get('https://google.com/', {}, function (err: any, res: any, payload: any) { /* do stuff */ }); @@ -23,17 +23,15 @@ var wreckWithTimeout = wreck.defaults({ // all attributes are optional var options = { maxBytes: 1048576, // 1 MB, default: unlimited - rejectUnauthorized: true, - downstreamRes: null, - agent: null, // Node Core http.Agent + rejectUnauthorized: true }; -var optionalCallback = function (err, res) { +var optionalCallback = function (err: any, res: any) { /* handle err if it exists, in which case res will be undefined */ // buffer the response stream - Wreck.read(res, null, function (err, body) { + Wreck.read(res, null, function (err: any, body: any) { /* do stuff */ }); }; diff --git a/wreck/wreck.d.ts b/wreck/wreck.d.ts index 7198de2bb..135b2f4f2 100644 --- a/wreck/wreck.d.ts +++ b/wreck/wreck.d.ts @@ -5,7 +5,7 @@ /// -declare module Wreck +declare module "wreck" { import http = require('http'); import stream = require('stream'); @@ -15,17 +15,17 @@ declare module Wreck { defaults: (options: any) => IWreckObject; - request: (method: string, uri: string, options: any = null, callback: (err: any, response: http.IncomingMessage) => void = null) => http.ClientRequest; + request: (method: string, uri: string, options: any, callback?: (err: any, response: http.IncomingMessage) => void) => http.ClientRequest; read: (response: http.IncomingMessage, options: any, callback: (err: any, payload: any) => void) => void; - get: (uri: string, options: any = null, callback: (err: any, response: http.IncomingMessage, payload: any) => void = null) => http.ClientRequest; - post: (uri: string, options: any = null, callback: (err: any, response: http.IncomingMessage, payload: any) => void = null) => http.ClientRequest; - patch: (uri: string, options: any = null, callback: (err: any, response: http.IncomingMessage, payload: any) => void = null) => http.ClientRequest; - put: (uri: string, options: any = null, callback: (err: any, response: http.IncomingMessage, payload: any) => void = null) => http.ClientRequest; - delete: (uri: string, options: any = null, callback: (err: any, response: http.IncomingMessage, payload: any) => void = null) => http.ClientRequest; + get: (uri: string, options: any, callback: (err: any, response: http.IncomingMessage, payload: any) => void) => http.ClientRequest; + post: (uri: string, options: any, callback: (err: any, response: http.IncomingMessage, payload: any) => void) => http.ClientRequest; + patch: (uri: string, options: any, callback: (err: any, response: http.IncomingMessage, payload: any) => void) => http.ClientRequest; + put: (uri: string, options: any, callback: (err: any, response: http.IncomingMessage, payload: any) => void) => http.ClientRequest; + delete: (uri: string, options: any, callback: (err: any, response: http.IncomingMessage, payload: any) => void) => http.ClientRequest; - toReadableStream: (payload: any, encoding: string = null) => stream.Readable; + toReadableStream: (payload: any, encoding?: string) => stream.Readable; parseCacheControl: (field: string) => any; @@ -35,11 +35,7 @@ declare module Wreck }; } -} - -declare module "wreck" -{ - var wreck: Wreck.IWreckObject; + var wreck: IWreckObject; export = wreck; } From 73a82c7c312f4a8df75d62605ef984b54fda9094 Mon Sep 17 00:00:00 2001 From: Marcin Porebski Date: Tue, 1 Dec 2015 15:39:21 +0100 Subject: [PATCH 3/3] Wreck 7.0.0 - naming convention fix --- wreck/wreck.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wreck/wreck.d.ts b/wreck/wreck.d.ts index 135b2f4f2..8bc7b2d24 100644 --- a/wreck/wreck.d.ts +++ b/wreck/wreck.d.ts @@ -11,9 +11,9 @@ declare module "wreck" import stream = require('stream'); - interface IWreckObject + interface WreckObject { - defaults: (options: any) => IWreckObject; + defaults: (options: any) => WreckObject; request: (method: string, uri: string, options: any, callback?: (err: any, response: http.IncomingMessage) => void) => http.ClientRequest; @@ -35,7 +35,7 @@ declare module "wreck" }; } - var wreck: IWreckObject; + var wreck: WreckObject; export = wreck; }