/* * Copyright (C) 2022 Klaus Reimer * See LICENSE.md for licensing information. */ type JournalEventUpdate = (from: FROM, to: TO) => void; /** Registered journal event updates. */ const journalEventUpdates = new Map(); /** * Registers a journal event update. * * @param event - Tje event name. * @param update - The update function to register. */ export function registerJournalEventUpdate( event: From["event"] & To["event"], update: (from: From, to: To) => void): void { journalEventUpdates.set(event, update as JournalEventUpdate); } /** Map from deprecated event names to new ones. */ const eventNameUpdates: Record = { ShipLockerMaterials: "ShipLocker", BackPack: "Backpack", BackPackMaterials: "Backpack" }; /** * Updates the given journal event if necessary. * * @param event - The journal event to update. */ export function updateJournalEvent(event: JournalEvent): void { const newEventName = eventNameUpdates[event.event]; if (newEventName != null) { event.event = newEventName; } journalEventUpdates.get(event.event)?.(event, event); } /** * Base interface shared by all journal event types. */ export interface JournalEvent { /** The time in GMT, ISO 8601. */ timestamp: string; /** The type of event. */ event: T; }