From b20dd136f7ee69cb697a668c11e62b56f194241a Mon Sep 17 00:00:00 2001 From: Matt Magurany Date: Fri, 4 Sep 2015 17:22:09 -0400 Subject: [PATCH 1/4] Add oboe node() function overload that accepts a map of callbacks. --- oboe/oboe.d.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/oboe/oboe.d.ts b/oboe/oboe.d.ts index 6e6ed650b..63d51796b 100644 --- a/oboe/oboe.d.ts +++ b/oboe/oboe.d.ts @@ -10,10 +10,9 @@ declare module "oboe" { function oboe(url: string): oboe.Oboe; function oboe(options: oboe.Options): oboe.Oboe; - function oboe(stream: stream.Readable) : oboe.Oboe; + function oboe(stream: stream.Readable): oboe.Oboe; module oboe { - var drop: {}; interface Oboe { @@ -22,6 +21,7 @@ declare module "oboe" { fail(callback: (result: FailReason) => void): Oboe; node(pattern: string, callback: CallbackSignature): Oboe; + node(patterns: PatternMap): Oboe; on(event: string, pattern: string, callback: CallbackSignature): Oboe; on(eventPattern: string, callback: CallbackSignature): Oboe; @@ -33,14 +33,14 @@ declare module "oboe" { removeListener(event: string, pattern: string, callback: CallbackSignature): Oboe; start(callback: (status: number, headers: Object) => void): Oboe; - + abort():void; source: string; } interface CallbackSignature { - (node: any, pathOrHeaders: any, ancestors: Object[]): any; + (node: any, pathOrHeaders: any, ancestors: Object[]): any; } interface Options { @@ -58,8 +58,11 @@ declare module "oboe" { body?: string; jsonBody?: Object; } + + interface PatternMap { + [pattern: string]: CallbackSignature + } } export = oboe; } - From db28808cdd015a29d4c8bc5020c14e9304b46a65 Mon Sep 17 00:00:00 2001 From: Matt Magurany Date: Fri, 4 Sep 2015 17:22:24 -0400 Subject: [PATCH 2/4] Add oboe node() function overload that accepts a map of callbacks. --- oboe/oboe.d.ts | 116 +++++++++++++++++++++++++------------------------ 1 file changed, 59 insertions(+), 57 deletions(-) diff --git a/oboe/oboe.d.ts b/oboe/oboe.d.ts index 63d51796b..b3bbb8d0c 100644 --- a/oboe/oboe.d.ts +++ b/oboe/oboe.d.ts @@ -5,64 +5,66 @@ /// -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; - node(patterns: PatternMap): 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; - - abort():void; - - 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?: Error; - statusCode?: number; - body?: string; - jsonBody?: Object; - } - - interface PatternMap { - [pattern: string]: CallbackSignature - } +declare module oboe { + interface OboeFunction extends Function { + drop: Object; + (url: string): oboe.Oboe; + (options: oboe.Options): oboe.Oboe; + (stream: NodeJS.ReadableStream): oboe.Oboe; } + interface Oboe { + done(callback: (result: any) => void): Oboe; + + fail(callback: (result: FailReason) => void): Oboe; + + node(pattern: string, callback: CallbackSignature): Oboe; + node(patterns: PatternMap): 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; + + abort():void; + + 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?: Error; + statusCode?: number; + body?: string; + jsonBody?: Object; + } + + interface PatternMap { + [pattern: string]: CallbackSignature + } +} + +declare var oboe: oboe.OboeFunction; + +declare module "oboe" { + var oboe: oboe.OboeFunction; export = oboe; } From 2d0fe2589b3370848bc9e0b15740ba3eca488839 Mon Sep 17 00:00:00 2001 From: Matt Magurany Date: Fri, 4 Sep 2015 22:08:15 -0400 Subject: [PATCH 3/4] Add tests for oboe node function and remove superfluous oboe declaration. --- oboe/oboe-tests.ts | 15 +++++++++++++++ oboe/oboe.d.ts | 1 - 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/oboe/oboe-tests.ts b/oboe/oboe-tests.ts index f98def75e..48939d418 100644 --- a/oboe/oboe-tests.ts +++ b/oboe/oboe-tests.ts @@ -32,3 +32,18 @@ oboe('/content') console.error('no such content'); } }); + +oboe('friends.json') + .node('friend', function (parsedJson) { + console.log('friend parsed', parsedJson); + }); + +oboe('friends.json') + .node({ + 'friend': function (parsedJson) { + console.log('friend parsed', parsedJson); + }, + '!': function (parsedJson) { + console.log('root parsed', parsedJson); + } + }); diff --git a/oboe/oboe.d.ts b/oboe/oboe.d.ts index b3bbb8d0c..754467de1 100644 --- a/oboe/oboe.d.ts +++ b/oboe/oboe.d.ts @@ -65,6 +65,5 @@ declare module oboe { declare var oboe: oboe.OboeFunction; declare module "oboe" { - var oboe: oboe.OboeFunction; export = oboe; } From 2ccd95e9507d8e92d641b827a480c1947dbe197d Mon Sep 17 00:00:00 2001 From: Matt Magurany Date: Fri, 4 Sep 2015 23:35:25 -0400 Subject: [PATCH 4/4] Remove superfluous oboe namespaces. --- oboe/oboe.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/oboe/oboe.d.ts b/oboe/oboe.d.ts index 754467de1..1f036ce8b 100644 --- a/oboe/oboe.d.ts +++ b/oboe/oboe.d.ts @@ -8,9 +8,9 @@ declare module oboe { interface OboeFunction extends Function { drop: Object; - (url: string): oboe.Oboe; - (options: oboe.Options): oboe.Oboe; - (stream: NodeJS.ReadableStream): oboe.Oboe; + (url: string): Oboe; + (options: Options): Oboe; + (stream: NodeJS.ReadableStream): Oboe; } interface Oboe {