refactor(core): Use type-safe event emitters (no-changelog) (#10234)
This commit is contained in:
committed by
GitHub
parent
99dc56c7a1
commit
1fca3af335
16
packages/cli/src/services/cache/cache.service.ts
vendored
16
packages/cli/src/services/cache/cache.service.ts
vendored
@@ -1,5 +1,3 @@
|
||||
import EventEmitter from 'node:events';
|
||||
|
||||
import Container, { Service } from 'typedi';
|
||||
import { caching } from 'cache-manager';
|
||||
import { ApplicationError, jsonStringify } from 'n8n-workflow';
|
||||
@@ -10,14 +8,20 @@ import { MalformedRefreshValueError } from '@/errors/cache-errors/malformed-refr
|
||||
import type {
|
||||
TaggedRedisCache,
|
||||
TaggedMemoryCache,
|
||||
CacheEvent,
|
||||
MaybeHash,
|
||||
Hash,
|
||||
} from '@/services/cache/cache.types';
|
||||
import { TIME } from '@/constants';
|
||||
import { TypedEmitter } from '@/TypedEmitter';
|
||||
|
||||
type CacheEvents = {
|
||||
'metrics.cache.hit': never;
|
||||
'metrics.cache.miss': never;
|
||||
'metrics.cache.update': never;
|
||||
};
|
||||
|
||||
@Service()
|
||||
export class CacheService extends EventEmitter {
|
||||
export class CacheService extends TypedEmitter<CacheEvents> {
|
||||
private cache: TaggedRedisCache | TaggedMemoryCache;
|
||||
|
||||
async init() {
|
||||
@@ -66,10 +70,6 @@ export class CacheService extends EventEmitter {
|
||||
await this.cache.store.reset();
|
||||
}
|
||||
|
||||
emit(event: CacheEvent, ...args: unknown[]) {
|
||||
return super.emit(event, ...args);
|
||||
}
|
||||
|
||||
isRedis() {
|
||||
return this.cache.kind === 'redis';
|
||||
}
|
||||
|
||||
@@ -8,5 +8,3 @@ export type TaggedMemoryCache = MemoryCache & { kind: 'memory' };
|
||||
export type Hash<T = unknown> = Record<string, T>;
|
||||
|
||||
export type MaybeHash<T> = Hash<T> | undefined;
|
||||
|
||||
export type CacheEvent = `metrics.cache.${'hit' | 'miss' | 'update'}`;
|
||||
|
||||
Reference in New Issue
Block a user