fixed some lint issues
This commit is contained in:
parent
8680b6ec20
commit
a700818a06
15 changed files with 1574 additions and 1319 deletions
15
libs/core/cache/src/cache-factory.ts
vendored
15
libs/core/cache/src/cache-factory.ts
vendored
|
|
@ -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';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
6
libs/core/cache/src/connection-manager.ts
vendored
6
libs/core/cache/src/connection-manager.ts
vendored
|
|
@ -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);
|
||||
|
|
|
|||
4
libs/core/cache/src/namespaced-cache.ts
vendored
4
libs/core/cache/src/namespaced-cache.ts
vendored
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
8
libs/core/cache/src/redis-cache.ts
vendored
8
libs/core/cache/src/redis-cache.ts
vendored
|
|
@ -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 [];
|
||||
}
|
||||
|
|
|
|||
2
libs/core/cache/src/types.ts
vendored
2
libs/core/cache/src/types.ts
vendored
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue