feat(server): use nestjs events to validate config (#7986)

* use events for config validation

* chore: better types

* add unit tests

---------

Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
Daniel Dietzler
2024-03-17 20:16:02 +01:00
committed by GitHub
parent 14da671bf9
commit 148428a564
14 changed files with 170 additions and 81 deletions
@@ -1,4 +1,5 @@
import { AssetResponseDto, ReleaseNotification, ServerVersionResponseDto } from '@app/domain';
import { SystemConfig } from '@app/infra/entities';
export const ICommunicationRepository = 'ICommunicationRepository';
@@ -21,6 +22,14 @@ export enum ServerEvent {
CONFIG_UPDATE = 'config:update',
}
export enum InternalEvent {
VALIDATE_CONFIG = 'validate_config',
}
export interface InternalEventMap {
[InternalEvent.VALIDATE_CONFIG]: { newConfig: SystemConfig; oldConfig: SystemConfig };
}
export interface ClientEventMap {
[ClientEvent.UPLOAD_SUCCESS]: AssetResponseDto;
[ClientEvent.USER_DELETE]: string;
@@ -45,4 +54,6 @@ export interface ICommunicationRepository {
on(event: 'connect', callback: OnConnectCallback): void;
on(event: ServerEvent, callback: OnServerEventCallback): void;
sendServerEvent(event: ServerEvent): void;
emit<E extends keyof InternalEventMap>(event: E, data: InternalEventMap[E]): boolean;
emitAsync<E extends keyof InternalEventMap>(event: E, data: InternalEventMap[E]): Promise<any>;
}