From 172f92448a1adbd33c48977b55197bd688ebc3b0 Mon Sep 17 00:00:00 2001 From: Jared Date: Fri, 2 Jan 2015 20:07:55 +1300 Subject: [PATCH 1/2] Add typings for oboe. --- oboe/oboe-tests.ts | 34 +++++++++++++++++++++++++ oboe/oboe.d.ts | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 oboe/oboe-tests.ts create mode 100644 oboe/oboe.d.ts diff --git a/oboe/oboe-tests.ts b/oboe/oboe-tests.ts new file mode 100644 index 000000000..cdf0129fc --- /dev/null +++ b/oboe/oboe-tests.ts @@ -0,0 +1,34 @@ +/// +import oboe = require('oboe'); + +oboe('friends.json') + .node('name', function (name) { + console.log('You have a friend called', name); + }).on('node', '{name dob address}', function (personJson) { + console.log('Name is: %s', personJson.name); + }).on('node', 'person.address', function (address) { + return oboe.drop; + }) + +var friendCount = 0; +oboe('friends.json') + .path('friend', function (name) { + friendCount++; + }); + +oboe('resource.json') + .on('done', function (parsedJson) { + console.log('Request complete', parsedJson); + }); + +oboe('resource.json') + .on('start', function (status, headers) { + console.log('Resource cached for', headers.Age, 'secs'); + }); + +oboe('/content') + .fail(function (errorReport) { + if (404 == errorReport.statusCode) { + console.error('no such content'); + } + }); diff --git a/oboe/oboe.d.ts b/oboe/oboe.d.ts new file mode 100644 index 000000000..b8dc4d92b --- /dev/null +++ b/oboe/oboe.d.ts @@ -0,0 +1,63 @@ +// Type definitions for [LIBRARY NAME] +// Project: [LIBRARY URL] +// Definitions by: [AUTHOR NAME] <[AUTHOR URL]> +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module "oboe" { + import stream = require('stream'); + + function oboe(url: string): oboe.Oboe; + function oboe(options: oboe.Options): oboe.Oboe; + function oboe(stream: stream.Readable) : oboe.Oboe; + + module oboe { + + var drop: {}; + + interface Oboe { + done(callback: (result: any) => void): Oboe; + + fail(callback: (result: FailReason) => void): Oboe; + + node(pattern: string, callback: CallbackSignature): Oboe; + + on(event: string, pattern: string, callback: CallbackSignature): Oboe; + on(eventPattern: string, callback: CallbackSignature): Oboe; + + path(pattern: string, callback: CallbackSignature): Oboe; + path(listeners: any): Oboe; + + removeListener(eventPattern: string, callback: CallbackSignature): Oboe; + removeListener(event: string, pattern: string, callback: CallbackSignature): Oboe; + + start(callback: (status: number, headers: Object) => void): Oboe; + + source: string; + } + + interface CallbackSignature { + (node: any, pathOrHeaders: any, ancestors: Object[]): any; + } + + interface Options { + url: string; + method?: string; + headers?: Object; + body?: any; + cached?: boolean; + withCredentials?: boolean; + } + + interface FailReason { + thrown?: string; + statusCode?: number; + body?: string; + jsonBody?: Object; + } + } + + export = oboe; +} + From 99471289d707e142f7b716b75675b66be7c0cfee Mon Sep 17 00:00:00 2001 From: Jared Date: Fri, 2 Jan 2015 20:18:09 +1300 Subject: [PATCH 2/2] Fix header and make use of tabs consistent in both tests and definition. --- oboe/oboe-tests.ts | 42 +++++++++++++++++++++--------------------- oboe/oboe.d.ts | 6 +++--- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/oboe/oboe-tests.ts b/oboe/oboe-tests.ts index cdf0129fc..f98def75e 100644 --- a/oboe/oboe-tests.ts +++ b/oboe/oboe-tests.ts @@ -2,33 +2,33 @@ import oboe = require('oboe'); oboe('friends.json') - .node('name', function (name) { - console.log('You have a friend called', name); - }).on('node', '{name dob address}', function (personJson) { - console.log('Name is: %s', personJson.name); - }).on('node', 'person.address', function (address) { - return oboe.drop; - }) + .node('name', function (name) { + console.log('You have a friend called', name); + }).on('node', '{name dob address}', function (personJson) { + console.log('Name is: %s', personJson.name); + }).on('node', 'person.address', function (address) { + return oboe.drop; + }) var friendCount = 0; oboe('friends.json') - .path('friend', function (name) { - friendCount++; - }); + .path('friend', function (name) { + friendCount++; + }); oboe('resource.json') - .on('done', function (parsedJson) { - console.log('Request complete', parsedJson); - }); + .on('done', function (parsedJson) { + console.log('Request complete', parsedJson); + }); oboe('resource.json') - .on('start', function (status, headers) { - console.log('Resource cached for', headers.Age, 'secs'); - }); + .on('start', function (status, headers) { + console.log('Resource cached for', headers.Age, 'secs'); + }); oboe('/content') - .fail(function (errorReport) { - if (404 == errorReport.statusCode) { - console.error('no such content'); - } - }); + .fail(function (errorReport) { + if (404 == errorReport.statusCode) { + console.error('no such content'); + } + }); diff --git a/oboe/oboe.d.ts b/oboe/oboe.d.ts index b8dc4d92b..d9f426133 100644 --- a/oboe/oboe.d.ts +++ b/oboe/oboe.d.ts @@ -1,6 +1,6 @@ -// Type definitions for [LIBRARY NAME] -// Project: [LIBRARY URL] -// Definitions by: [AUTHOR NAME] <[AUTHOR URL]> +// Type definitions for oboe v2.0.3 +// Project: https://github.com/jimhigson/oboe.js +// Definitions by: Jared Klopper // Definitions: https://github.com/borisyankov/DefinitelyTyped ///