update type params

This commit is contained in:
Erik 2023-05-08 02:42:39 +03:00
parent 91fe66b202
commit 8b20ae60bf
Signed by: Navy.gif
GPG Key ID: 2532FBBB61C65A68
5 changed files with 13 additions and 11 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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);
}

View File

@ -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>
}

View File

@ -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' });