fix: code review cleanup - remove unused imports, replace any types with generics, fix test imports

This commit is contained in:
Jason Woltje
2026-01-30 00:12:27 -06:00
parent f074c3c689
commit 2c7faf5241
3 changed files with 20 additions and 21 deletions

View File

@@ -30,8 +30,7 @@ import { KnowledgeCacheService } from "./services/cache.service";
export class KnowledgeController {
constructor(
private readonly knowledgeService: KnowledgeService,
private readonly linkSync: LinkSyncService,
private readonly cache: KnowledgeCacheService
private readonly linkSync: LinkSyncService
) {}
/**

View File

@@ -1,3 +1,4 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { Test, TestingModule } from '@nestjs/testing';
import { KnowledgeCacheService } from './cache.service';

View File

@@ -37,7 +37,6 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
private readonly ENTRY_PREFIX = 'knowledge:entry:';
private readonly SEARCH_PREFIX = 'knowledge:search:';
private readonly GRAPH_PREFIX = 'knowledge:graph:';
private readonly STATS_PREFIX = 'knowledge:stats:';
// Default TTL from environment (default: 5 minutes)
private readonly DEFAULT_TTL: number;
@@ -113,7 +112,7 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
/**
* Get entry from cache by workspace and slug
*/
async getEntry(workspaceId: string, slug: string): Promise<any | null> {
async getEntry<T = unknown>(workspaceId: string, slug: string): Promise<T | null> {
if (!this.cacheEnabled) return null;
try {
@@ -124,7 +123,7 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
this.stats.hits++;
this.updateHitRate();
this.logger.debug(`Cache HIT: ${key}`);
return JSON.parse(cached);
return JSON.parse(cached) as T;
}
this.stats.misses++;
@@ -140,10 +139,10 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
/**
* Set entry in cache
*/
async setEntry(
async setEntry<T = unknown>(
workspaceId: string,
slug: string,
data: any,
data: T,
options?: CacheOptions
): Promise<void> {
if (!this.cacheEnabled) return;
@@ -182,11 +181,11 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
/**
* Get search results from cache
*/
async getSearch(
async getSearch<T = unknown>(
workspaceId: string,
query: string,
filters: Record<string, any>
): Promise<any | null> {
filters: Record<string, unknown>
): Promise<T | null> {
if (!this.cacheEnabled) return null;
try {
@@ -197,7 +196,7 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
this.stats.hits++;
this.updateHitRate();
this.logger.debug(`Cache HIT: ${key}`);
return JSON.parse(cached);
return JSON.parse(cached) as T;
}
this.stats.misses++;
@@ -213,11 +212,11 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
/**
* Set search results in cache
*/
async setSearch(
async setSearch<T = unknown>(
workspaceId: string,
query: string,
filters: Record<string, any>,
data: any,
filters: Record<string, unknown>,
data: T,
options?: CacheOptions
): Promise<void> {
if (!this.cacheEnabled) return;
@@ -254,11 +253,11 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
/**
* Get graph query results from cache
*/
async getGraph(
async getGraph<T = unknown>(
workspaceId: string,
entryId: string,
maxDepth: number
): Promise<any | null> {
): Promise<T | null> {
if (!this.cacheEnabled) return null;
try {
@@ -269,7 +268,7 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
this.stats.hits++;
this.updateHitRate();
this.logger.debug(`Cache HIT: ${key}`);
return JSON.parse(cached);
return JSON.parse(cached) as T;
}
this.stats.misses++;
@@ -285,11 +284,11 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
/**
* Set graph query results in cache
*/
async setGraph(
async setGraph<T = unknown>(
workspaceId: string,
entryId: string,
maxDepth: number,
data: any,
data: T,
options?: CacheOptions
): Promise<void> {
if (!this.cacheEnabled) return;
@@ -399,7 +398,7 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
private getSearchKey(
workspaceId: string,
query: string,
filters: Record<string, any>
filters: Record<string, unknown>
): string {
const filterHash = this.hashObject(filters);
return `${this.SEARCH_PREFIX}${workspaceId}:${query}:${filterHash}`;
@@ -419,7 +418,7 @@ export class KnowledgeCacheService implements OnModuleInit, OnModuleDestroy {
/**
* Hash an object to create a consistent string representation
*/
private hashObject(obj: Record<string, any>): string {
private hashObject(obj: Record<string, unknown>): string {
return JSON.stringify(obj, Object.keys(obj).sort());
}