diff --git a/types/rate-limit-redis/index.d.ts b/types/rate-limit-redis/index.d.ts new file mode 100644 index 0000000000..101ac813dd --- /dev/null +++ b/types/rate-limit-redis/index.d.ts @@ -0,0 +1,19 @@ +// Type definitions for rate-limit-redis 1.6 +// Project: https://github.com/wyattjoh/rate-limit-redis#readme +// Definitions by: Chris Suich +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.7 + +import { RedisClient } from 'redis'; +import { Store } from 'express-rate-limit'; + +interface RedisStoreOptions { + expiry?: number; + prefix?: string; + resetExpiryOnChange?: boolean; + client?: RedisClient; +} + +declare function RedisStore(options?: RedisStoreOptions): Store; + +export = RedisStore; diff --git a/types/rate-limit-redis/package.json b/types/rate-limit-redis/package.json new file mode 100644 index 0000000000..0686410b7e --- /dev/null +++ b/types/rate-limit-redis/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "express-rate-limit": ">=3.4.0" + } +} diff --git a/types/rate-limit-redis/rate-limit-redis-tests.ts b/types/rate-limit-redis/rate-limit-redis-tests.ts new file mode 100644 index 0000000000..8126d81df3 --- /dev/null +++ b/types/rate-limit-redis/rate-limit-redis-tests.ts @@ -0,0 +1,28 @@ +import { RedisClient } from 'redis'; +import RedisStore from 'rate-limit-redis'; +import { Store } from 'express-rate-limit'; + +let store: Store; + +// $ExpectType Store +store = RedisStore(); + +// $ExpectType Store +store = RedisStore({ + expiry: 1000, +}); + +// $ExpectType Store +store = RedisStore({ + prefix: 'types', +}); + +// $ExpectType Store +store = RedisStore({ + resetExpiryOnChange: false, +}); + +// $ExpectType Store +store = RedisStore({ + client: new RedisClient({}), +}); diff --git a/types/rate-limit-redis/tsconfig.json b/types/rate-limit-redis/tsconfig.json new file mode 100644 index 0000000000..832848e488 --- /dev/null +++ b/types/rate-limit-redis/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "esModuleInterop": true + }, + "files": [ + "index.d.ts", + "rate-limit-redis-tests.ts" + ] +} diff --git a/types/rate-limit-redis/tslint.json b/types/rate-limit-redis/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/rate-limit-redis/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }