Add superagent and supertest definitions

This commit is contained in:
Alex Varju
2013-09-05 15:44:29 -07:00
parent a58894f898
commit edd97d5bd5
4 changed files with 165 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
/// <reference path="superagent.d.ts" />
import superagent = require('superagent')
var agent = superagent.agent();
agent
.post('http://localhost:3000/signin')
.send({ email: 'test@dummy.com', password: 'bacon' })
.end((err, res) => {
if (err) throw err;
if (res.status !== 200) throw new Error('bad status ' + res.status);
});
+84
View File
@@ -0,0 +1,84 @@
// Type definitions for SuperAgent 0.15.4
// Project: https://github.com/visionmedia/superagent
// Definitions by: Alex Varju <https://github.com/varju/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path='../node/node.d.ts' />
declare module "superagent" {
export interface Response {
text: string;
body: Object;
header: Object;
type: string;
charset: string;
status: number;
statusType: number;
info: boolean;
ok: boolean;
redirect: boolean;
clientError: boolean;
serverError: boolean;
error: any;
accepted: boolean;
noContent: boolean;
badRequest: boolean;
unauthorized: boolean;
notAcceptable: boolean;
notFound: boolean;
forbidden: boolean;
get(header: string): string;
}
export interface Request {
attach(field: string, file: string, filename: string): Request;
redirects(n: number): Request;
part(): Request;
set(field: string, val: string): Request;
set(field: Object): Request;
get(field: string): string;
type(val: string): Request;
query(val: Object): Request;
send(data: string): Request;
send(data: Object): Request;
write(data: string, encoding: string): boolean;
write(data: NodeBuffer, encoding: string): boolean;
pipe(stream: WritableStream, options?: Object): WritableStream;
buffer(val: boolean): Request;
timeout(ms: number): Request;
clearTimeout(): Request;
abort(): void;
auth(user: string, name: string): Request;
field(name: string, val: string): Request;
end(callback?: (err: Error, res: Response) => void): Request;
}
export interface Agent {
get(url: string, callback?: (err: Error, res: Response) => void): Request;
post(url: string, callback?: (err: Error, res: Response) => void): Request;
put(url: string, callback?: (err: Error, res: Response) => void): Request;
head(url: string, callback?: (err: Error, res: Response) => void): Request;
del(url: string, callback?: (err: Error, res: Response) => void): Request;
options(url: string, callback?: (err: Error, res: Response) => void): Request;
trace(url: string, callback?: (err: Error, res: Response) => void): Request;
copy(url: string, callback?: (err: Error, res: Response) => void): Request;
lock(url: string, callback?: (err: Error, res: Response) => void): Request;
mkcol(url: string, callback?: (err: Error, res: Response) => void): Request;
move(url: string, callback?: (err: Error, res: Response) => void): Request;
propfind(url: string, callback?: (err: Error, res: Response) => void): Request;
proppatch(url: string, callback?: (err: Error, res: Response) => void): Request;
unlock(url: string, callback?: (err: Error, res: Response) => void): Request;
report(url: string, callback?: (err: Error, res: Response) => void): Request;
mkactivity(url: string, callback?: (err: Error, res: Response) => void): Request;
checkout(url: string, callback?: (err: Error, res: Response) => void): Request;
merge(url: string, callback?: (err: Error, res: Response) => void): Request;
//m-search(url: string, callback?: (err: Error, res: Response) => void): Request;
notify(url: string, callback?: (err: Error, res: Response) => void): Request;
subscribe(url: string, callback?: (err: Error, res: Response) => void): Request;
unsubscribe(url: string, callback?: (err: Error, res: Response) => void): Request;
patch(url: string, callback?: (err: Error, res: Response) => void): Request;
parse(fn: Function): Request;
}
export function agent(): Agent;
}