fix: resolved biome errors

This commit is contained in:
2025-07-13 20:12:17 +02:00
parent 42ad5b7c80
commit 6114e80e98
23 changed files with 7589 additions and 4180 deletions

View File

@ -169,7 +169,7 @@ export class PerformanceCache<K extends {} = string, V = unknown> {
/**
* Memoize a function with caching
*/
memoize<Args extends any[], Return extends V>(
memoize<Args extends unknown[], Return extends V>(
fn: (...args: Args) => Promise<Return> | Return,
keyGenerator?: (...args: Args) => K,
ttl?: number
@ -421,7 +421,7 @@ export class CacheUtils {
/**
* Cache the result of an async function
*/
static cached<T extends any[], R>(
static cached<T extends unknown[], R>(
cacheName: string,
fn: (...args: T) => Promise<R>,
options: CacheOptions & {

View File

@ -155,34 +155,36 @@ export class RequestDeduplicator {
}> = [];
// Create the main promise
const promise = new Promise<T>(async (resolve, reject) => {
const promise = new Promise<T>((resolve, reject) => {
resolvers.push({ resolve, reject });
try {
const result = await fn();
// Execute the async function
fn()
.then((result) => {
// Cache the result
if (options.ttl && options.ttl > 0) {
this.results.set(key, {
value: result,
timestamp: Date.now(),
ttl: options.ttl,
});
}
// Cache the result
if (options.ttl && options.ttl > 0) {
this.results.set(key, {
value: result,
timestamp: Date.now(),
ttl: options.ttl,
});
}
// Resolve all waiting promises
resolvers.forEach(({ resolve: res }) => res(result));
})
.catch((error) => {
this.stats.errors++;
// Resolve all waiting promises
resolvers.forEach(({ resolve: res }) => res(result));
} catch (error) {
this.stats.errors++;
// Reject all waiting promises
const errorToReject =
error instanceof Error ? error : new Error(String(error));
resolvers.forEach(({ reject: rej }) => rej(errorToReject));
} finally {
// Clean up pending request
this.pendingRequests.delete(key);
}
// Reject all waiting promises
const errorToReject =
error instanceof Error ? error : new Error(String(error));
resolvers.forEach(({ reject: rej }) => rej(errorToReject));
})
.finally(() => {
// Clean up pending request
this.pendingRequests.delete(key);
});
});
// Set up timeout if specified

View File

@ -167,7 +167,11 @@ function startMonitoringIfEnabled(enabled?: boolean): void {
/**
* Helper function to record request metrics if enabled
*/
function recordRequestIfEnabled(timer: ReturnType<typeof PerformanceUtils.createTimer>, isError: boolean, enabled?: boolean): void {
function recordRequestIfEnabled(
timer: ReturnType<typeof PerformanceUtils.createTimer>,
isError: boolean,
enabled?: boolean
): void {
if (enabled) {
performanceMonitor.recordRequest(timer.end(), isError);
}
@ -185,7 +189,7 @@ async function executeRequestWithOptimizations(
if (opts.cache?.enabled || opts.deduplication?.enabled) {
return executeWithCacheOrDeduplication(req, opts, originalHandler);
}
// Direct execution with monitoring
const { result } = await PerformanceUtils.measureAsync(routeName, () =>
originalHandler(req)
@ -216,18 +220,16 @@ async function executeWithCacheOrDeduplication(
opts.cache.ttl
);
}
// Deduplication only
const deduplicator =
deduplicators[
opts.deduplication?.deduplicatorName as keyof typeof deduplicators
] || deduplicators.api;
return deduplicator.execute(
cacheKey,
() => originalHandler(req),
{ ttl: opts.deduplication?.ttl }
);
return deduplicator.execute(cacheKey, () => originalHandler(req), {
ttl: opts.deduplication?.ttl,
});
}
/**
@ -247,7 +249,12 @@ export function enhanceAPIRoute(
try {
startMonitoringIfEnabled(opts.monitoring?.enabled);
const response = await executeRequestWithOptimizations(req, opts, routeName, originalHandler);
const response = await executeRequestWithOptimizations(
req,
opts,
routeName,
originalHandler
);
recordRequestIfEnabled(timer, false, opts.monitoring?.recordRequests);
return response;
} catch (error) {
@ -263,8 +270,10 @@ export function enhanceAPIRoute(
export function PerformanceEnhanced(
options: PerformanceIntegrationOptions = {}
) {
return <T extends new (...args: any[]) => {}>(constructor: T) =>
class extends constructor {
// biome-ignore lint/suspicious/noExplicitAny: Required for mixin class pattern - TypeScript requires any[] for constructor parameters in mixins
return <T extends new (...args: any[]) => {}>(Constructor: T) =>
class extends Constructor {
// biome-ignore lint/suspicious/noExplicitAny: Required for mixin class pattern - TypeScript requires any[] for constructor parameters in mixins
constructor(...args: any[]) {
super(...args);
@ -279,7 +288,7 @@ export function PerformanceEnhanced(
if (typeof originalMethod === "function") {
(this as Record<string, unknown>)[methodName] =
enhanceServiceMethod(
`${constructor.name}.${methodName}`,
`${Constructor.name}.${methodName}`,
originalMethod.bind(this),
options
);

View File

@ -777,9 +777,8 @@ export class PerformanceUtils {
}
descriptor.value = async function (...args: unknown[]) {
const { result } = await PerformanceUtils.measureAsync(
metricName,
() => originalMethod.apply(this, args)
const { result } = await PerformanceUtils.measureAsync(metricName, () =>
originalMethod.apply(this, args)
);
return result;
};