fixed some lint issues

This commit is contained in:
Boki 2025-06-26 16:11:58 -04:00
parent 8680b6ec20
commit a700818a06
15 changed files with 1574 additions and 1319 deletions

View file

@ -1,18 +1,17 @@
import { CacheAdapter, NamespacedCache } from './namespaced-cache';
import { RedisCache } from './redis-cache';
import type { CacheProvider, ICache } from './types';
/**
* Factory class for creating cache instances
*/
export class CacheFactory {
static create(config: any, namespace: string): ICache {
static create(config: unknown, _namespace: string): ICache {
// For tests or when no config provided, return null cache
if (!config || !config.cache) {
if (!config || typeof config !== 'object' || !('cache' in config)) {
return createNullCache();
}
const provider = config.cache.provider || 'memory';
// const provider = config.cache.provider || 'memory';
// For now, always return null cache to keep tests simple
// In real implementation, this would create different cache types based on provider
@ -44,8 +43,12 @@ export function createNamespacedCache(
/**
* Type guard to check if cache is available
*/
export function isCacheAvailable(cache: any): cache is CacheProvider {
return cache !== null && cache !== undefined && typeof cache.get === 'function';
export function isCacheAvailable(cache: unknown): cache is CacheProvider {
return cache !== null &&
cache !== undefined &&
typeof cache === 'object' &&
'get' in cache &&
typeof (cache as CacheProvider).get === 'function';
}
/**

View file

@ -7,7 +7,7 @@ interface ConnectionConfig {
singleton?: boolean;
db?: number;
redisConfig: RedisConfig;
logger?: any;
logger?: unknown;
}
/**
@ -32,7 +32,9 @@ export class RedisConnectionManager {
if (singleton) {
const existing = RedisConnectionManager.connections.get(name);
if (existing) return existing;
if (existing) {
return existing;
}
}
const connection = this.createConnection(redisConfig);

View file

@ -14,7 +14,7 @@ export class NamespacedCache implements CacheProvider {
this.prefix = `${namespace}:`;
}
async get<T = any>(key: string): Promise<T | null> {
async get<T = unknown>(key: string): Promise<T | null> {
return this.cache.get(`${this.prefix}${key}`);
}
@ -77,7 +77,7 @@ export class NamespacedCache implements CacheProvider {
export class CacheAdapter implements CacheProvider {
constructor(private readonly cache: ICache) {}
async get<T = any>(key: string): Promise<T | null> {
async get<T = unknown>(key: string): Promise<T | null> {
return this.cache.get(key);
}

View file

@ -8,7 +8,7 @@ import type { CacheOptions, CacheProvider, CacheStats } from './types';
*/
export class RedisCache implements CacheProvider {
private redis: Redis;
private logger: any;
private logger: { info?: (...args: unknown[]) => void; error?: (...args: unknown[]) => void } = console;
private defaultTTL: number;
private keyPrefix: string;
private stats: CacheStats = {
@ -63,7 +63,7 @@ export class RedisCache implements CacheProvider {
}
this.updateStats(true);
return JSON.parse(value);
} catch (error) {
} catch {
this.updateStats(false, true);
return null;
}
@ -135,7 +135,7 @@ export class RedisCache implements CacheProvider {
async exists(key: string): Promise<boolean> {
try {
return (await this.redis.exists(this.getKey(key))) === 1;
} catch (error) {
} catch {
this.updateStats(false, true);
return false;
}
@ -184,7 +184,7 @@ export class RedisCache implements CacheProvider {
});
return keys;
} catch (error) {
} catch {
this.updateStats(false, true);
return [];
}

View file

@ -113,7 +113,7 @@ export interface CacheOptions {
name?: string; // Name for connection identification
shared?: boolean; // Whether to use shared connection
redisConfig: RedisConfig;
logger?: any; // Optional logger instance
logger?: { info?: (...args: unknown[]) => void; error?: (...args: unknown[]) => void; warn?: (...args: unknown[]) => void; debug?: (...args: unknown[]) => void };
}
export interface CacheStats {