update type params
This commit is contained in:
parent
91fe66b202
commit
8b20ae60bf
@ -20,7 +20,7 @@ import { Util } from '../util/index.js';
|
||||
import { Registry, UserDatabase } from './components/index.js';
|
||||
import { Authenticator, RateLimiter } from './middleware/index.js';
|
||||
import { UserDatabaseInterface } from './interfaces/index.js';
|
||||
import { ExternalProfile, OAuthProvider, Request, Response, ServerOptions, SessionLimit } from '../../@types/Server.js';
|
||||
import { ExternalProfile, OAuthProvider, Request, Response, ServerOptions } from '../../@types/Server.js';
|
||||
import { MongoMemory } from './database/index.js';
|
||||
import { IPCMessage, SignupCode } from '../../@types/Other.js';
|
||||
import { DoneCallback } from 'passport';
|
||||
@ -52,7 +52,7 @@ class Server extends EventEmitter {
|
||||
#_registry: Registry;
|
||||
#_mariadb: MariaDB;
|
||||
#_mongodb: MongoDB;
|
||||
#_memoryStoreProvider: MongoMemory<string, SessionLimit>;
|
||||
#_memoryStoreProvider: MongoMemory;
|
||||
#_rateLimiter: RateLimiter;
|
||||
#_authenticator: Authenticator;
|
||||
|
||||
|
@ -2,11 +2,13 @@ import Server from "../Server.js";
|
||||
import { MemoryCacheProvider } from "../interfaces/index.js";
|
||||
|
||||
class MemoryCache<K, V> {
|
||||
|
||||
server: Server;
|
||||
provider: MemoryCacheProvider<K, V>;
|
||||
provider: MemoryCacheProvider;
|
||||
collection: string;
|
||||
|
||||
constructor (server: Server, { provider, collection }: {
|
||||
provider: MemoryCacheProvider<K, V>,
|
||||
provider: MemoryCacheProvider,
|
||||
collection?: string
|
||||
}) {
|
||||
this.server = server;
|
||||
|
@ -1,16 +1,16 @@
|
||||
import { MongoDB } from '@navy.gif/wrappers';
|
||||
import { MemoryCacheProvider } from '../interfaces/index.js';
|
||||
|
||||
class MongoMemory<K, V> extends MongoDB implements MemoryCacheProvider<K, V> {
|
||||
class MongoMemory extends MongoDB implements MemoryCacheProvider {
|
||||
|
||||
async getKey (key: K, collection = 'memoryStore'): Promise<V | null> {
|
||||
async getKey<K, V> (key: K, collection = 'memoryStore'): Promise<V | null> {
|
||||
const response = await this.findOne(collection, { key });
|
||||
if (response)
|
||||
return response.value as V;
|
||||
return null;
|
||||
}
|
||||
|
||||
async setKey (key: K, value: V, collection = 'memoryStore'): Promise<void> {
|
||||
async setKey (key: unknown, value: unknown, collection = 'memoryStore'): Promise<void> {
|
||||
await this.updateOne(collection, { key }, { value }, true);
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
interface MemoryCacheProvider<K, V> {
|
||||
interface MemoryCacheProvider {
|
||||
|
||||
ensureIndex(collection: string, indices: string[]): Promise<void>
|
||||
getKey(key: K, collection?: string): Promise<V | null>
|
||||
setKey(key: K, value: V, collection?: string): Promise<void>
|
||||
getKey<K, V>(key: K, collection?: string): Promise<V | null>
|
||||
setKey(key: unknown, value: unknown, collection?: string): Promise<void>
|
||||
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ class RateLimiter {
|
||||
* @param {*} [options={}]
|
||||
* @memberof RateLimiter
|
||||
*/
|
||||
constructor (server: Server, memoryCacheProvider: MemoryCacheProvider<string, SessionLimit>, { limitFn }: RateLimiterOptions = {}) {
|
||||
constructor (server: Server, memoryCacheProvider: MemoryCacheProvider, { limitFn }: RateLimiterOptions = {}) {
|
||||
|
||||
this.server = server;
|
||||
this.cache = new MemoryCache<string, SessionLimit>(server, { provider: memoryCacheProvider, collection: 'rateLimiter' });
|
||||
|
Loading…
Reference in New Issue
Block a user