mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 04:50:18 +00:00
update types for restify 7.2 and move typing for v5 to v5 folder
This commit is contained in:
Vendored
+21
-28
@@ -1,6 +1,9 @@
|
||||
// Type definitions for restify 7.2
|
||||
// Project: https://github.com/restify/node-restify
|
||||
// Definitions by: Bret Little <https://github.com/blittle>, Steve Hipwell <https://github.com/stevehipwell>, Leandro Almeida <https://github.com/leanazulyoro>, Mitchell Bundy <https://github.com/mgebundy>
|
||||
// Definitions by: Bret Little <https://github.com/blittle>
|
||||
// Steve Hipwell <https://github.com/stevehipwell>
|
||||
// Leandro Almeida <https://github.com/leanazulyoro>
|
||||
// Mitchell Bundy <https://github.com/mgebundy>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
@@ -102,7 +105,7 @@ export interface Server extends http.Server {
|
||||
* Wraps node's close().
|
||||
* @param callback optional callback to invoke when done.
|
||||
*/
|
||||
close(callback?: Function): any;
|
||||
close(callback?: () => any): any;
|
||||
|
||||
/**
|
||||
* Returns the number of currently inflight requests.
|
||||
@@ -254,10 +257,10 @@ export interface Server extends http.Server {
|
||||
|
||||
/** enable DTrace support */
|
||||
dtrace: boolean;
|
||||
|
||||
|
||||
/** Custom response formatters */
|
||||
formatters: Formatters;
|
||||
|
||||
|
||||
/** Prevents calling next multiple times */
|
||||
onceNext: boolean;
|
||||
|
||||
@@ -273,10 +276,10 @@ export interface Server extends http.Server {
|
||||
|
||||
http2?: boolean;
|
||||
|
||||
ca: ServerOptions['ca']
|
||||
ca: ServerOptions['ca'];
|
||||
|
||||
certificate: ServerOptions['certificate'];
|
||||
|
||||
certificate: ServerOptions['certificate']
|
||||
|
||||
key: ServerOptions['key'];
|
||||
|
||||
passphrase: ServerOptions['passphrase'] | null;
|
||||
@@ -292,16 +295,16 @@ export interface ChainOptions {
|
||||
|
||||
export interface Chain {
|
||||
/** Get handlers of a chain instance */
|
||||
getHandlers(): Function[];
|
||||
getHandlers(): RequestHandler[];
|
||||
|
||||
/** Utilize the given middleware `handler` */
|
||||
add(handler: Function): void;
|
||||
add(handler: RequestHandler): void;
|
||||
|
||||
/** Returns the number of handlers */
|
||||
count(): number;
|
||||
|
||||
/** Handle server requests, punting them down the middleware stack. */
|
||||
run(req: Request, res: Response, done: Function): void;
|
||||
run(req: Request, res: Response, done: () => any): void;
|
||||
|
||||
/** Prevents calling next multiple times */
|
||||
onceNext: boolean;
|
||||
@@ -346,11 +349,11 @@ export interface RouterOptions {
|
||||
|
||||
ignoreTrailingSlash?: boolean;
|
||||
|
||||
registry?: RouterRegistryRadix;
|
||||
registry?: RouterRegistryRadix;
|
||||
}
|
||||
|
||||
export interface Router {
|
||||
constructor(options: RouterOptions): void;
|
||||
export class Router {
|
||||
constructor(options: RouterOptions);
|
||||
|
||||
/**
|
||||
* Lookup for route
|
||||
@@ -384,7 +387,7 @@ export interface Router {
|
||||
/**
|
||||
* Default route, when no route found
|
||||
*/
|
||||
defaultRoute(req: Request, res: Response, next: Function): void;
|
||||
defaultRoute(req: Request, res: Response, next: Next): void;
|
||||
|
||||
/**
|
||||
* toString() serialization.
|
||||
@@ -808,21 +811,11 @@ export interface Response extends http.ServerResponse {
|
||||
* redirect is sugar method for redirecting.
|
||||
* res.redirect({...}, next);
|
||||
* `next` is mandatory, to complete the response and trigger audit logger.
|
||||
* @param url to redirect to
|
||||
* @param url to redirect to or options object to configure a redirect or
|
||||
* @param next - mandatory, to complete the response and trigger audit logger
|
||||
* @emits redirect
|
||||
*/
|
||||
redirect(url: string, next: Next): void;
|
||||
|
||||
/**
|
||||
* redirect is sugar method for redirecting.
|
||||
* res.redirect({...}, next);
|
||||
* `next` is mandatory, to complete the response and trigger audit logger.
|
||||
* @param opts - options object to configure a redirect
|
||||
* @param next - mandatory, to complete the response and trigger audit logger
|
||||
* @emits redirect
|
||||
*/
|
||||
redirect(opts: RedirectOptions, next: Next): void;
|
||||
redirect(opts: string | RedirectOptions, next: Next): void;
|
||||
|
||||
/** HTTP status code. */
|
||||
code: number;
|
||||
@@ -870,7 +863,7 @@ export interface RedirectOptions {
|
||||
* by default, will merge the two.
|
||||
*/
|
||||
overrideQuery?: boolean;
|
||||
|
||||
|
||||
/**
|
||||
* if true, sets 301. defaults to 302.
|
||||
*/
|
||||
@@ -961,7 +954,7 @@ export interface ServerUpgradeResponse {
|
||||
* Ends the response
|
||||
*/
|
||||
end(): boolean;
|
||||
|
||||
|
||||
/**
|
||||
* Write to the response.
|
||||
*/
|
||||
|
||||
Vendored
+1343
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,191 @@
|
||||
import * as restify from "restify";
|
||||
import * as url from "url";
|
||||
import * as Logger from "bunyan";
|
||||
import * as http from "http";
|
||||
import * as stream from "stream";
|
||||
|
||||
let server: restify.Server;
|
||||
|
||||
server = restify.createServer({
|
||||
formatters: {
|
||||
'application/foo': function formatFoo(req: restify.Request, res: restify.Response, body: any) {
|
||||
if (body instanceof Error)
|
||||
return body.stack;
|
||||
|
||||
if (body)
|
||||
return body.toString('base64');
|
||||
|
||||
return body;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
server = restify.createServer({});
|
||||
|
||||
server.pre(restify.pre.sanitizePath());
|
||||
|
||||
server.on('someEvent', () => { });
|
||||
|
||||
server.use((req: restify.Request, res: restify.Response, next: restify.Next) => { });
|
||||
server.use([(req: restify.Request, res: restify.Response, next: restify.Next) => { }, (req: restify.Request, res: restify.Response, next: restify.Next) => { }]);
|
||||
server.use((req: restify.Request, res: restify.Response, next: restify.Next) => { }, (req: restify.Request, res: restify.Response, next: restify.Next) => { });
|
||||
|
||||
function send(req: restify.Request, res: restify.Response, next: restify.Next) {
|
||||
req.header('key', 'val');
|
||||
req.header('key') === 'val';
|
||||
req.trailer('key', 'val');
|
||||
req.trailer('key') === 'val';
|
||||
|
||||
let b: boolean;
|
||||
b = req.accepts('test');
|
||||
b = req.accepts(['test']);
|
||||
b = req.acceptsEncoding('test');
|
||||
b = req.acceptsEncoding(['test']);
|
||||
b = req.is('test');
|
||||
b = req.isChunked();
|
||||
b = req.isKeepAlive();
|
||||
b = req.isSecure();
|
||||
b = req.isUpgradeRequest();
|
||||
b = req.isUpload();
|
||||
req.userAgent() === 'test';
|
||||
req.startHandlerTimer('test');
|
||||
req.endHandlerTimer('test');
|
||||
|
||||
const log = req.log;
|
||||
log.debug({ params: req.params }, 'Hello there %s', 'foo');
|
||||
|
||||
req.getContentLength() === 50;
|
||||
req.contentLength() === 50;
|
||||
req.getContentType() === 'test';
|
||||
req.contentType() === 'test';
|
||||
req.getHref() === 'test';
|
||||
req.href() === 'test';
|
||||
req.getId() === 'test';
|
||||
req.id() === 'test';
|
||||
req.getPath() === 'test';
|
||||
req.path() === 'test';
|
||||
req.getQuery() === 'test';
|
||||
req.query === 'test';
|
||||
req.time() === 1463518410080;
|
||||
req.getUrl() === url.parse('https://test.test.test/test');
|
||||
req.getVersion() === 'test';
|
||||
req.version() === 'test';
|
||||
req.params;
|
||||
res.header('test');
|
||||
res.header('test', {});
|
||||
res.header('test', new Date());
|
||||
|
||||
res.cache();
|
||||
res.cache('testst', { maxAge: 60 });
|
||||
res.cache({ maxAge: 60 });
|
||||
|
||||
res.status(344);
|
||||
|
||||
res.send({ hello: 'world' });
|
||||
res.send(201, { hello: 'world' });
|
||||
res.send(new Error('meh'));
|
||||
|
||||
res.json(201, { hello: 'world' });
|
||||
res.json({ hello: 'world' });
|
||||
|
||||
res.code === 50;
|
||||
res.contentLength === 50;
|
||||
res.charSet('test');
|
||||
res.contentType === 'test';
|
||||
res.headers;
|
||||
res.id === 'test';
|
||||
|
||||
res.send('hello ' + req.params.name);
|
||||
res.writeHead(200);
|
||||
res.writeHead(200, {
|
||||
"Content-Type": "application/json"
|
||||
});
|
||||
next();
|
||||
}
|
||||
|
||||
server.post('/hello', send);
|
||||
server.put('/hello', send);
|
||||
server.del('/hello', send);
|
||||
server.get('/hello', send);
|
||||
server.head('/hello', send);
|
||||
server.opts('/hello', send);
|
||||
|
||||
server.post(/(.*)/, send);
|
||||
server.put(/(.*)/, send);
|
||||
server.del(/(.*)/, send);
|
||||
server.get(/(.*)/, send);
|
||||
server.head(/(.*)/, send);
|
||||
server.opts(/(.*)/, send);
|
||||
|
||||
server.name = "";
|
||||
server.versions = [""];
|
||||
server.acceptable = ["test"];
|
||||
server.url = "";
|
||||
server.server = new http.Server();
|
||||
|
||||
server.address().port;
|
||||
server.address().family;
|
||||
server.address().address;
|
||||
|
||||
server.listen("somePath", send);
|
||||
server.close();
|
||||
|
||||
server.use(restify.plugins.acceptParser(server.acceptable));
|
||||
server.use(restify.plugins.authorizationParser());
|
||||
server.use(restify.plugins.dateParser());
|
||||
server.use(restify.plugins.queryParser());
|
||||
server.use(restify.plugins.jsonp());
|
||||
server.use(restify.plugins.gzipResponse());
|
||||
server.use(restify.plugins.bodyParser());
|
||||
server.use(restify.plugins.throttle({
|
||||
burst: 100,
|
||||
rate: 50,
|
||||
ip: true,
|
||||
overrides: {
|
||||
'192.168.1.1': {
|
||||
rate: 0,
|
||||
burst: 0
|
||||
}
|
||||
}
|
||||
}));
|
||||
server.use(restify.plugins.conditionalHandler([{
|
||||
contentType: ['text/plain'],
|
||||
handler: (req: restify.Request, res: restify.Response, next: restify.Next): void => {
|
||||
res.send('OK');
|
||||
next();
|
||||
},
|
||||
version: '0.0.0',
|
||||
}]));
|
||||
|
||||
const logger = Logger.createLogger({ name: "test" });
|
||||
|
||||
server.on('after', restify.plugins.auditLogger({ event: 'after', log: logger }));
|
||||
|
||||
server.on('after', (req: restify.Request, res: restify.Response, route: restify.Route, err: any) => {
|
||||
route.spec.method === 'GET';
|
||||
route.spec.name === 'routeName';
|
||||
route.spec.path === '/some/path';
|
||||
route.spec.path === /\/some\/path\/.*/;
|
||||
route.spec.versions === ['v1'];
|
||||
restify.plugins.auditLogger({ event: 'after', log: logger })(req, res, route, err);
|
||||
});
|
||||
|
||||
(<any> restify).defaultResponseHeaders = function(this: restify.Request, data: any) {
|
||||
this.header('Server', 'helloworld');
|
||||
};
|
||||
|
||||
const loggerStream: Logger.Stream = {};
|
||||
|
||||
const requestCaptureOptions: restify.bunyan.RequestCaptureOptions = {};
|
||||
requestCaptureOptions.stream = loggerStream;
|
||||
requestCaptureOptions.streams = Object.freeze([loggerStream, loggerStream]);
|
||||
requestCaptureOptions.level = Logger.DEBUG;
|
||||
requestCaptureOptions.level = "info";
|
||||
requestCaptureOptions.maxRecords = 50;
|
||||
requestCaptureOptions.maxRequestIds = 500;
|
||||
requestCaptureOptions.dumpDefault = true;
|
||||
|
||||
const requestCaptureStream = new restify.bunyan.RequestCaptureStream(requestCaptureOptions);
|
||||
const asStream: stream.Stream = requestCaptureStream;
|
||||
|
||||
const logger2: Logger = restify.bunyan.createLogger("horse");
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../../",
|
||||
"typeRoots": [
|
||||
"../../"
|
||||
],
|
||||
"paths": {
|
||||
"restify": [
|
||||
"restify/v5"
|
||||
]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"restify-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
// TODO
|
||||
"no-unnecessary-class": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user