Merge pull request #7627 from cyrilschumacher/master

Add (and update) several definitions
This commit is contained in:
Masahiro Wakame
2016-01-23 22:21:01 +09:00
11 changed files with 409 additions and 76 deletions
-1
View File
@@ -1 +0,0 @@
--noImplicitAny
+4 -4
View File
@@ -3,10 +3,10 @@
/// <reference path="../cookie-parser/cookie-parser.d.ts" />
/// <reference path="../express/express.d.ts" />
import express = require("express");
import timeout = require("connect-timeout");
import bodyParser = require("body-parser");
import cookieParser = require("cookie-parser");
import * as express from "express";
import timeout from "connect-timeout";
import * as bodyParser from "body-parser";
import * as cookieParser from "cookie-parser";
// example of using this top-level; note the use of haltOnTimedout
// after every middleware; it will stop the request flow on a timeout
+5 -2
View File
@@ -23,6 +23,10 @@ declare module Express {
declare module "connect-timeout" {
import express = require("express");
/**
* @summary Interface for timeout options.
* @interface
*/
interface TimeoutOptions extends Object {
/**
* @summary Controls if this module will "respond" in the form of forwarding an error.
@@ -31,6 +35,5 @@ declare module "connect-timeout" {
respond: boolean;
}
function timeout(timeout: string, options?: TimeoutOptions): express.RequestHandler;
export = timeout;
export default function timeout(timeout: string, options?: TimeoutOptions): express.RequestHandler;
}
@@ -0,0 +1,18 @@
/// <reference path="../express-brute/express-brute.d.ts"/>
/// <reference path="../mongodb/mongodb.d.ts"/>
/// <reference path="express-brute-memcached.d.ts"/>
import express = require("express");
import ExpressBrute = require("express-brute");
import MemcachedStore = require("express-brute-memcached");
var app = express();
var store = new MemcachedStore("127.0.0.1");
var bruteforce = new ExpressBrute(store);
app.post('/auth',
bruteforce.prevent, // error 403 if we hit this route too often
function (req, res, next) {
res.send('Success!');
}
);
+114
View File
@@ -0,0 +1,114 @@
// Type definitions for express-brute-memcached
// Project: https://github.com/AdamPflug/express-brute-memcached
// Definitions by: Cyril Schumacher <https://github.com/cyrilschumacher/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../express/express.d.ts" />
declare module "express-brute-memcached" {
/**
* @summary Memcached options.
* @interface
*/
interface MemcachedStoreOptions {
prefix: string;
/**
* @summary Maximum key size allowed.
* @type {number}
*/
maxKeySize: number;
/**
* @summary Maximum expiration time of keys (in seconds).
* @type {number}
*/
maxExpiration: number;
/**
* @summary Maximum size of a value.
* @type {number}
*/
maxValue: number;
/**
* @summary Maximum size of the connection pool.
* @type {number}
*/
poolSize: number;
/**
* @summary Hashing algorithm used to generate the hashRing values
* @type {string}
*/
algorithm: string;
/**
* @summary Time between reconnection attempts (in milliseconds).
* @type {number}
*/
reconnect: number;
/**
* @summary Time after which Memcached sends a connection timeout (in milliseconds).
* @type {number}
*/
timeout: number;
/**
* @summary Number of socket allocation retries per request.
* @type {number}
*/
retries: number;
/**
* @summary Number of failed-attempts to a server before it is regarded as 'dead'.
* @type {number}
*/
failures: number;
/**
* @summary Time between a server failure and an attempt to set it up back in service.
* @type {number}
*/
retry: number;
/**
* @summary If true, authorizes the automatic removal of dead servers from the pool.
* @type {boolean}
*/
remove: boolean;
/**
* @summary An array of server_locations to replace servers that fail and that are removed from the consistent hashing scheme.
* @type {Array}
*/
failOverServers: Array<any>;
/**
* @summary True, whether to use md5 as hashing scheme when keys exceed maxKeySize .
* @type
*/
keyCompression: boolean;
/**
* @summary Idle timeout for the connections.
* @type {number}
*/
idle: number;
}
/**
* @summary A memcached store adapter.
* @class
*/
export = class MemcachedStore {
/**
* @summary Constructor.
* @constructor
* @param {string|Array} hosts The collection.
* @param {Object} options The otpions.
*/
constructor(hosts: string|Array<string>, options?: MemcachedStoreOptions);
}
}
+82 -66
View File
@@ -45,85 +45,101 @@ declare module "express-brute" {
}
/**
* @summary Middleware.
* @summary Options for {@link ExpressBrute} class.
* @interface
*/
interface ExpressBruteOptions {
freeRetries: number;
proxyDepth: number;
attachResetToRequest: boolean;
refreshTimeoutOnRequest: boolean;
minWait: number;
maxWait: number;
lifetime: number;
failCallback: (req: express.Request, res: express.Response, next: Function, nextValidRequestDate: any) => void;
handleStoreError: any;
}
/**
* @summary Middleware.
* @class
*/
class ExpressBrute {
/**
* @summary Constructor.
* @constructor
* @param {any} store The store.
*/
constructor(store: any);
/**
* @summary Generates middleware that will bounce requests with the same key and IP address that happen faster than the current wait time by calling failCallback.
* @param {Object} options The options.
*/
getMiddleware(options: ExpressBruteMiddleware): express.RequestHandler;
/**
* @summary Uses the current proxy trust settings to get the current IP from a request object.
* @param {Request} request The HTTP request.
* @return {RequestHandler} The Request handler.
*/
getIPFromRequest(request: express.Request): express.RequestHandler;
/**
* @summary Middleware that will bounce requests that happen faster than the current wait time by calling failCallback.
* @param {Request} request The HTTP request.
* @param {Response} response The HTTP response.
* @param {Function} next The next middleware.
* @return {RequestHandler} The Request handler.
*/
prevent(request: express.Request, response: express.Response, next: Function): express.RequestHandler;
/**
* @summary Resets the wait time between requests back to its initial value.
* @param {string} ip The IP address.
* @param {string} key The key. response.
* @param {Function} next The next middleware.
* @return {RequestHandler} The Request handler.
*/
reset(ip: string, key: string, next: Function): express.RequestHandler;
}
module ExpressBrute {
/**
* @summary In-memory store.
* @class
*/
class ExpressBrute {
export class MemoryStore {
/**
* @summary Constructor.
* @constructor
* @param {any} store The store.
*/
constructor(store: any);
/**
* @summary Generates middleware that will bounce requests with the same key and IP address that happen faster than the current wait time by calling failCallback.
* @param {Object} options The options.
*/
getMiddleware(options: ExpressBruteMiddleware): express.RequestHandler;
constructor(options?: MemoryStoreOptions);
/**
* @summary Gets key value.
* @param {string} key The key name.
* @param {Function} callbck The callback.
*/
get(key: string, callback: (error: any, data: Object) => void): void;
/**
* @summary Uses the current proxy trust settings to get the current IP from a request object.
* @param {Request} request The HTTP request.
* @return {RequestHandler} The Request handler.
* @summary Sets the key value.
* @param {string} key The name.
* @param {string} value The value.
* @param {number} lifetime The lifetime.
* @param {Function} callback The callback.
*/
getIPFromRequest(request: express.Request): express.RequestHandler;
set(key: string, value: any, lifetime: number, callback: (error: any) => void): void;
/**
* @summary Middleware that will bounce requests that happen faster than the current wait time by calling failCallback.
* @param {Request} request The HTTP request.
* @param {Response} response The HTTP response.
* @param {Function} next The next middleware.
* @return {RequestHandler} The Request handler.
* @summary Deletes the key.
* @param {string} key The name.
* @param {Function} callback The callback.
*/
prevent(request: express.Request, response: express.Response, next: Function): express.RequestHandler;
/**
* @summary Resets the wait time between requests back to its initial value.
* @param {string} ip The IP address.
* @param {string} key The key. response.
* @param {Function} next The next middleware.
* @return {RequestHandler} The Request handler.
*/
reset(ip: string, key: string, next: Function): express.RequestHandler;
reset(key: string, callback: (error: any) => void): void;
}
}
module ExpressBrute {
/**
* @summary In-memory store.
* @class
*/
export class MemoryStore {
/**
* @summary Constructor.
* @constructor
* @param {Object} options The options.
*/
constructor(options?: MemoryStoreOptions);
/**
* @summary Gets key value.
* @param {string} key The key name.
* @param {Function} callbck The callback.
*/
get(key: string, callback: (error: any, data: Object) => void): void;
/**
* @summary Sets the key value.
* @param {string} key The name.
* @param {string} value The value.
* @param {number} lifetime The lifetime.
* @param {Function} callback The callback.
*/
set(key: string, value: any, lifetime: number, callback: (error: any) => void): void;
/**
* @summary Deletes the key.
* @param {string} key The name.
* @param {Function} callback The callback.
*/
reset(key: string, callback: (error: any) => void): void;
}
}
export = ExpressBrute;
export = ExpressBrute;
}
@@ -0,0 +1,48 @@
///<reference path="../i18next/i18next.d.ts"/>
///<reference path="i18next-express-middleware.d.ts"/>
import * as express from "express";
import * as i18next from "i18next";
import middleware = require("i18next-express-middleware");
function requestObjectTest() {
var i18nextOptions = {};
i18next
.use(middleware.LanguageDetector)
.init(i18nextOptions);
var app = express();
app.use(middleware.handle(i18next, {
ignoreRoutes: ["/foo"],
removeLngFromUrl: false
}));
}
function detectorOptionsTest() {
var options = {
// order and from where user language should be detected
order: [/*'path', 'session', */ 'querystring', 'cookie', 'header'],
// keys or params to lookup language from
lookupQuerystring: 'lng',
lookupCookie: 'i18next',
lookupSession: 'lng',
lookupFromPathIndex: 0,
// cache user language
caches: false, // ['cookie']
// optional expire and domain for set cookie
cookieExpirationDate: new Date(),
cookieDomain: 'myDomain'
};
i18next
.use(middleware.LanguageDetector)
.init({
detection: options
});
var lngDetector = new middleware.LanguageDetector(null, options);
lngDetector.init(options);
}
@@ -0,0 +1,96 @@
// Type definitions for i18next-express-middleware
// Project: http://i18next.com/
// Definitions by: Cyril Schumacher <https://github.com/cyrilschumacher>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
///<reference path="../express/express.d.ts"/>
///<reference path="../i18next/i18next.d.ts"/>
/**
* @summary Interface for Language detector options.
* @interface
*/
interface LanguageDetectorOptions {
caches?: boolean;
cookieDomain?: string;
cookieExpirationDate?: Date;
lookupCookie?: string;
lookupFromPathIndex?: number;
lookupQuerystring?: string;
lookupSession?: string;
order?: Array<string>;
}
declare module "i18next-express-middleware" {
import express = require("express");
import i18next = require("i18next");
/**
* @summary Interface for middleware to use i18next in express.js.
* @interface
*/
export interface i18nextExpressMiddleware {
LanguageDetector(): express.Handler;
missingKeyHandler(): express.Handler;
}
/**
* @summary Interface for own detection functionality.
*/
export interface i18nextCustomDetection {
name: string;
lookup: (req: express.Request, res: express.Response, options?: Object) => void;
cacheUserLanguage: (req: express.Request, res: express.Response, lng?: any, options?: Object) => void;
}
/**
* @summary Detects user language from current request.
* @class
*/
export class LanguageDetector {
/**
* @summary Constructor.
* @constructor
* @param {any} services The services.
* @param {Object} options The options.
* @param {Object} allOptions The all options.
*/
constructor(services?: any, options?: Object, allOptions?: Object);
/**
* @summary Adds detector.
* @param {i18nextCustomDetection} detector The detector to add.
*/
addDetector(detector: i18nextCustomDetection): void;
// NOTE: add documentation
cacheUserLanguage(req: express.Request, res: express.Response, detectionOrder: any): void;
/**
* @summary Detects the language.
* @param {Request} req The HTTP request.
* @param {Response} res The HTTP response.
* @param {detectionOrder} detectionOrder The detection order.
*/
detect(req: express.Request, res: express.Response, detectionOrder: any): void;
/**
* @summary Initializes class.
* @param {any} services The services.
* @param {Object} options The options.
* @param {Object} allOptions The all options.
*/
init(services: any, options?: Object, allOptions?: Object): void;
}
export function getResourcesHandler(i18next: I18nextStatic, options: Object): express.Handler;
export function handle(i18next: I18nextStatic, options?: Object): express.Handler;
/**
* @summary Gets handler for missing key.
* @param {I18nextStatic} i18next The i18next.
* @param {Object} options The options.
* @return {express.Handler} The express handler.
*/
export function missingKeyHandler(i18next: I18nextStatic, options: Object): express.Handler;
}
@@ -0,0 +1,10 @@
///<reference path="i18next-sprintf-postprocessor.d.ts"/>
import * as i18next from "i18next";
import sprintf from "i18next-sprintf-postprocessor";
function initTest() {
const i18nextOptions = {};
i18next.use(sprintf).init(i18nextOptions);
i18next.init({ overloadTranslationOptionHandler: sprintf.overloadTranslationOptionHandler });
}
@@ -0,0 +1,20 @@
// Type definitions for i18next-sprintf-postProcessor
// Project: https://github.com/i18next/i18next-sprintf-postProcessor
// Definitions by: Cyril Schumacher <https://github.com/cyrilschumacher>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
///<reference path="../express/express.d.ts"/>
///<reference path="../i18next/i18next.d.ts"/>
declare module "i18next-sprintf-postprocessor" {
import i18next = require("i18next");
interface i18nextSprintfPostProcessor {
(): any;
process(value: any, key: string, options: Object): void;
overloadTranslationOptionHandler(args: Array<any>): void;
}
var sprintf: i18nextSprintfPostProcessor;
export default sprintf;
}
+12 -3
View File
@@ -1,11 +1,14 @@
// Type definitions for i18next v1.5.10
// Type definitions for i18next v2.0.17
// Project: http://i18next.com
// Definitions by: Maarten Docter <https://github.com/mdocter>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
// Sources: https://github.com/jamuhl/i18next/
/// <reference path="../express/express.d.ts" />
/// <reference path="../jquery/jquery.d.ts" />
/// <reference path="../i18next-express-middleware/i18next-express-middleware.d.ts" />
/// <reference path="../i18next-sprintf-postprocessor/i18next-sprintf-postprocessor.d.ts" />
interface IResourceStore {
[language: string]: IResourceStoreLanguage;
@@ -27,7 +30,12 @@ interface I18nTranslateOptions extends I18nextOptions {
context?: any;
}
interface I18nextOptions {
interface i18nextSprintfPostProcessorStatic {
overloadTranslationOptionHandler?(args: Array<any>): void;
process?(value: any, key: string, options: Object): void;
}
interface I18nextOptions extends i18nextSprintfPostProcessorStatic {
lng?: string; // Default value: undefined
load?: string; // Default value: 'all'
preload?: string[]; // Default value: []
@@ -99,7 +107,7 @@ interface I18nextStatic {
regexEscape(str: string): string;
};
init(callback?: (err: any, t: (key: string, options?: any) => string) => void ): JQueryDeferred<any>;
init(options?: I18nextOptions, callback?: (err: any, t: (key: string, options?: any) => string) => void ): JQueryDeferred<any>;
init(options?: I18nextOptions|any, callback?: (err: any, t: (key: string, options?: any) => string) => void ): JQueryDeferred<any>; // NOTE: remove any for 'options' parameter.
lng(): string;
loadNamespace(namespace: string, callback?: () => void ): void;
loadNamespaces(namespaces: string[], callback?: () => void ): void;
@@ -124,6 +132,7 @@ interface I18nextStatic {
t(key: string, options?: I18nTranslateOptions): string;
translate(key: string, options?: I18nTranslateOptions): string;
exists(key: string, options?: any): boolean;
use(module: any): I18nextStatic;
}
// jQuery extensions