2024-03-20 23:53:07 +01:00
|
|
|
import { AssetResponseDto } from 'src/dtos/asset-response.dto';
|
|
|
|
|
import { ReleaseNotification, ServerVersionResponseDto } from 'src/dtos/server-info.dto';
|
2024-03-20 16:02:51 -05:00
|
|
|
import { SystemConfig } from 'src/entities/system-config.entity';
|
2024-02-18 23:50:32 +01:00
|
|
|
|
2023-02-25 09:12:03 -05:00
|
|
|
export const ICommunicationRepository = 'ICommunicationRepository';
|
|
|
|
|
|
2023-12-13 12:23:51 -05:00
|
|
|
export enum ClientEvent {
|
2023-02-25 09:12:03 -05:00
|
|
|
UPLOAD_SUCCESS = 'on_upload_success',
|
2024-03-08 17:49:39 -05:00
|
|
|
USER_DELETE = 'on_user_delete',
|
2023-10-06 15:48:11 -05:00
|
|
|
ASSET_DELETE = 'on_asset_delete',
|
|
|
|
|
ASSET_TRASH = 'on_asset_trash',
|
2023-10-22 02:38:07 +00:00
|
|
|
ASSET_UPDATE = 'on_asset_update',
|
2023-12-06 14:56:09 +00:00
|
|
|
ASSET_HIDDEN = 'on_asset_hidden',
|
2023-10-16 18:01:38 +00:00
|
|
|
ASSET_RESTORE = 'on_asset_restore',
|
2024-02-18 23:50:32 +01:00
|
|
|
ASSET_STACK_UPDATE = 'on_asset_stack_update',
|
2023-10-06 15:48:11 -05:00
|
|
|
PERSON_THUMBNAIL = 'on_person_thumbnail',
|
|
|
|
|
SERVER_VERSION = 'on_server_version',
|
2023-10-06 07:01:14 +00:00
|
|
|
CONFIG_UPDATE = 'on_config_update',
|
2023-10-24 17:05:42 +02:00
|
|
|
NEW_RELEASE = 'on_new_release',
|
2023-02-25 09:12:03 -05:00
|
|
|
}
|
|
|
|
|
|
2023-12-13 12:23:51 -05:00
|
|
|
export enum ServerEvent {
|
|
|
|
|
CONFIG_UPDATE = 'config:update',
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 20:16:02 +01:00
|
|
|
export enum InternalEvent {
|
|
|
|
|
VALIDATE_CONFIG = 'validate_config',
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface InternalEventMap {
|
|
|
|
|
[InternalEvent.VALIDATE_CONFIG]: { newConfig: SystemConfig; oldConfig: SystemConfig };
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-18 23:50:32 +01:00
|
|
|
export interface ClientEventMap {
|
|
|
|
|
[ClientEvent.UPLOAD_SUCCESS]: AssetResponseDto;
|
2024-03-08 17:49:39 -05:00
|
|
|
[ClientEvent.USER_DELETE]: string;
|
2024-02-18 23:50:32 +01:00
|
|
|
[ClientEvent.ASSET_DELETE]: string;
|
|
|
|
|
[ClientEvent.ASSET_TRASH]: string[];
|
|
|
|
|
[ClientEvent.ASSET_UPDATE]: AssetResponseDto;
|
|
|
|
|
[ClientEvent.ASSET_HIDDEN]: string;
|
|
|
|
|
[ClientEvent.ASSET_RESTORE]: string[];
|
|
|
|
|
[ClientEvent.ASSET_STACK_UPDATE]: string[];
|
|
|
|
|
[ClientEvent.PERSON_THUMBNAIL]: string;
|
|
|
|
|
[ClientEvent.SERVER_VERSION]: ServerVersionResponseDto;
|
|
|
|
|
[ClientEvent.CONFIG_UPDATE]: Record<string, never>;
|
|
|
|
|
[ClientEvent.NEW_RELEASE]: ReleaseNotification;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-05 23:23:06 +01:00
|
|
|
export type OnConnectCallback = (userId: string) => void | Promise<void>;
|
2023-12-13 12:23:51 -05:00
|
|
|
export type OnServerEventCallback = () => Promise<void>;
|
2023-10-24 17:05:42 +02:00
|
|
|
|
2023-02-25 09:12:03 -05:00
|
|
|
export interface ICommunicationRepository {
|
2024-02-18 23:50:32 +01:00
|
|
|
send<E extends keyof ClientEventMap>(event: E, userId: string, data: ClientEventMap[E]): void;
|
|
|
|
|
broadcast<E extends keyof ClientEventMap>(event: E, data: ClientEventMap[E]): void;
|
2023-12-13 12:23:51 -05:00
|
|
|
on(event: 'connect', callback: OnConnectCallback): void;
|
|
|
|
|
on(event: ServerEvent, callback: OnServerEventCallback): void;
|
|
|
|
|
sendServerEvent(event: ServerEvent): void;
|
2024-03-17 20:16:02 +01:00
|
|
|
emit<E extends keyof InternalEventMap>(event: E, data: InternalEventMap[E]): boolean;
|
|
|
|
|
emitAsync<E extends keyof InternalEventMap>(event: E, data: InternalEventMap[E]): Promise<any>;
|
2023-02-25 09:12:03 -05:00
|
|
|
}
|