Calendar/wwwroot/js/repositories/IEventRepository.d.ts
2026-02-03 00:02:25 +01:00

51 lines
2 KiB
TypeScript

import { ICalendarEvent } from '../types/CalendarTypes';
/**
* Update source type
* - 'local': Changes made by the user locally (needs sync)
* - 'remote': Changes from API/SignalR (already synced)
*/
export type UpdateSource = 'local' | 'remote';
/**
* IEventRepository - Interface for event data access
*
* Abstracts the data source for calendar events, allowing easy switching
* between IndexedDB, REST API, GraphQL, or other data sources.
*
* Implementations:
* - IndexedDBEventRepository: Local storage with offline support
* - MockEventRepository: (Legacy) Loads from local JSON file
* - ApiEventRepository: (Future) Loads from backend API
*/
export interface IEventRepository {
/**
* Load all calendar events from the data source
* @returns Promise resolving to array of ICalendarEvent objects
* @throws Error if loading fails
*/
loadEvents(): Promise<ICalendarEvent[]>;
/**
* Create a new event
* @param event - Event to create (without ID, will be generated)
* @param source - Source of the update ('local' or 'remote')
* @returns Promise resolving to the created event with generated ID
* @throws Error if creation fails
*/
createEvent(event: Omit<ICalendarEvent, 'id'>, source?: UpdateSource): Promise<ICalendarEvent>;
/**
* Update an existing event
* @param id - ID of the event to update
* @param updates - Partial event data to update
* @param source - Source of the update ('local' or 'remote')
* @returns Promise resolving to the updated event
* @throws Error if update fails or event not found
*/
updateEvent(id: string, updates: Partial<ICalendarEvent>, source?: UpdateSource): Promise<ICalendarEvent>;
/**
* Delete an event
* @param id - ID of the event to delete
* @param source - Source of the update ('local' or 'remote')
* @returns Promise resolving when deletion is complete
* @throws Error if deletion fails or event not found
*/
deleteEvent(id: string, source?: UpdateSource): Promise<void>;
}