mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Make RedisStore a class and expose RedisStoreOptions in rate-l… (#43113)
* Expose RedisStoreOptions in rate-limit-redis * Also refactor to expose RedisStore as a class instead of a variable * Rename RedisStore.RedisStoreOptions to RedisStore.Options so it is less redundant and is consistent with RateLimit.Options from express-rate-limit.
This commit is contained in:
parent
f377d05079
commit
f4073ff58a
29
types/rate-limit-redis/index.d.ts
vendored
29
types/rate-limit-redis/index.d.ts
vendored
@ -8,18 +8,27 @@
|
||||
|
||||
import { RedisClient } from 'redis';
|
||||
import IORedis = require('ioredis');
|
||||
import { Store } from 'express-rate-limit';
|
||||
import { Store, StoreIncrementCallback } from 'express-rate-limit';
|
||||
|
||||
interface RedisStoreOptions {
|
||||
expiry?: number;
|
||||
prefix?: string;
|
||||
resetExpiryOnChange?: boolean;
|
||||
client?: RedisClient | IORedis.Redis;
|
||||
redisURL?: string;
|
||||
declare namespace RedisStore {
|
||||
interface Options {
|
||||
expiry?: number;
|
||||
prefix?: string;
|
||||
resetExpiryOnChange?: boolean;
|
||||
client?: RedisClient | IORedis.Redis;
|
||||
redisURL?: string;
|
||||
}
|
||||
}
|
||||
|
||||
declare var RedisStore: {
|
||||
new (options?: RedisStoreOptions): Store;
|
||||
};
|
||||
declare class RedisStore implements Store {
|
||||
constructor(options?: RedisStore.Options);
|
||||
incr(key: string, cb: StoreIncrementCallback): void;
|
||||
decrement(key: string): void;
|
||||
resetKey(key: string): void;
|
||||
// rate-limit-redis 1.7.0 doesn't actually implement resetAll() and
|
||||
// express-rate-limit 5.1.1 doesn't actually call it, but it's required by
|
||||
// the Store interface so it's included here.
|
||||
resetAll(): void;
|
||||
}
|
||||
|
||||
export = RedisStore;
|
||||
|
||||
@ -1,39 +1,38 @@
|
||||
import { RedisClient } from 'redis';
|
||||
import IORedis = require('ioredis');
|
||||
import RedisStore from 'rate-limit-redis';
|
||||
import { Store } from 'express-rate-limit';
|
||||
|
||||
let store: Store;
|
||||
let store: RedisStore;
|
||||
|
||||
// $ExpectType Store
|
||||
// $ExpectType RedisStore
|
||||
store = new RedisStore();
|
||||
|
||||
// $ExpectType Store
|
||||
// $ExpectType RedisStore
|
||||
store = new RedisStore({
|
||||
expiry: 1000,
|
||||
});
|
||||
|
||||
// $ExpectType Store
|
||||
// $ExpectType RedisStore
|
||||
store = new RedisStore({
|
||||
prefix: 'types',
|
||||
});
|
||||
|
||||
// $ExpectType Store
|
||||
// $ExpectType RedisStore
|
||||
store = new RedisStore({
|
||||
resetExpiryOnChange: false,
|
||||
});
|
||||
|
||||
// $ExpectType Store
|
||||
// $ExpectType RedisStore
|
||||
store = new RedisStore({
|
||||
client: new RedisClient({}),
|
||||
});
|
||||
|
||||
// $ExpectType Store
|
||||
// $ExpectType RedisStore
|
||||
store = new RedisStore({
|
||||
client: new IORedis({}),
|
||||
});
|
||||
|
||||
// $ExpectType Store
|
||||
// $ExpectType RedisStore
|
||||
store = new RedisStore({
|
||||
redisURL: 'redis://localhost:6379',
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user