Merge pull request #3398 from optical/oboe

Oboe
This commit is contained in:
Masahiro Wakame
2015-01-02 20:12:50 +09:00
2 changed files with 97 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
/// <reference path="oboe.d.ts" />
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');
}
});
+63
View File
@@ -0,0 +1,63 @@
// Type definitions for oboe v2.0.3
// Project: https://github.com/jimhigson/oboe.js
// Definitions by: Jared Klopper <https://github.com/optical>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
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;
}