mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
Ensure shuttle repository uses typed EventEmitter overrides
This commit is contained in:
@@ -1,9 +1,31 @@
|
||||
import { IEta, IOrderedStop, IRoute, IShuttle, IStop } from "../../entities/ShuttleRepositoryEntities";
|
||||
import type EventEmitter from "node:events";
|
||||
|
||||
export const ShuttleRepositoryEvent = {
|
||||
ETA_UPDATED: "etaUpdated",
|
||||
ETA_REMOVED: "etaRemoved",
|
||||
ETA_DATA_CLEARED: "etaDataCleared",
|
||||
} as const;
|
||||
|
||||
export type ShuttleRepositoryEventName = typeof ShuttleRepositoryEvent[keyof typeof ShuttleRepositoryEvent];
|
||||
|
||||
export type EtaRemovedEventPayload = IEta;
|
||||
export type EtaDataClearedEventPayload = IEta[];
|
||||
|
||||
export interface ShuttleRepositoryEventPayloads {
|
||||
[ShuttleRepositoryEvent.ETA_UPDATED]: IEta;
|
||||
[ShuttleRepositoryEvent.ETA_REMOVED]: EtaRemovedEventPayload;
|
||||
[ShuttleRepositoryEvent.ETA_DATA_CLEARED]: EtaDataClearedEventPayload;
|
||||
}
|
||||
|
||||
export type ShuttleRepositoryEventListener<T extends ShuttleRepositoryEventName> = (
|
||||
payload: ShuttleRepositoryEventPayloads[T],
|
||||
) => void;
|
||||
|
||||
/**
|
||||
* Shuttle getter repository to be linked to a system.
|
||||
*/
|
||||
export interface ShuttleGetterRepository {
|
||||
export interface ShuttleGetterRepository extends EventEmitter {
|
||||
getStops(): Promise<IStop[]>;
|
||||
getStopById(stopId: string): Promise<IStop | null>;
|
||||
|
||||
@@ -18,23 +40,11 @@ export interface ShuttleGetterRepository {
|
||||
getEtasForStopId(stopId: string): Promise<IEta[]>;
|
||||
getEtaForShuttleAndStopId(shuttleId: string, stopId: string): Promise<IEta | null>;
|
||||
|
||||
/**
|
||||
* Subscribe to all updates in ETA data.
|
||||
* The subscriber persists even if the ETA data does not
|
||||
* exist within the repository, and may fire again
|
||||
* if ETA data is restored.
|
||||
* @param listener
|
||||
*/
|
||||
subscribeToEtaUpdates(
|
||||
listener: (eta: IEta) => void,
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Unsubscribe from all ETA updates for the given callback.
|
||||
* Callback must be passed by reference.
|
||||
* @param listener
|
||||
*/
|
||||
unsubscribeFromEtaUpdates(listener: (eta: IEta) => void): void;
|
||||
on<T extends ShuttleRepositoryEventName>(event: T, listener: ShuttleRepositoryEventListener<T>): this;
|
||||
once<T extends ShuttleRepositoryEventName>(event: T, listener: ShuttleRepositoryEventListener<T>): this;
|
||||
off<T extends ShuttleRepositoryEventName>(event: T, listener: ShuttleRepositoryEventListener<T>): this;
|
||||
addListener<T extends ShuttleRepositoryEventName>(event: T, listener: ShuttleRepositoryEventListener<T>): this;
|
||||
removeListener<T extends ShuttleRepositoryEventName>(event: T, listener: ShuttleRepositoryEventListener<T>): this;
|
||||
|
||||
getOrderedStopByRouteAndStopId(routeId: string, stopId: string): Promise<IOrderedStop | null>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user