98 lines
2.4 KiB
TypeScript
98 lines
2.4 KiB
TypeScript
|
|
import { ICalendarEvent } from '../types/CalendarTypes';
|
||
|
|
/**
|
||
|
|
* Operation for the sync queue
|
||
|
|
*/
|
||
|
|
export interface IQueueOperation {
|
||
|
|
id: string;
|
||
|
|
type: 'create' | 'update' | 'delete';
|
||
|
|
eventId: string;
|
||
|
|
data: Partial<ICalendarEvent> | ICalendarEvent;
|
||
|
|
timestamp: number;
|
||
|
|
retryCount: number;
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* IndexedDB Service for Calendar App
|
||
|
|
* Handles local storage of events and sync queue
|
||
|
|
*/
|
||
|
|
export declare class IndexedDBService {
|
||
|
|
private static readonly DB_NAME;
|
||
|
|
private static readonly DB_VERSION;
|
||
|
|
private static readonly EVENTS_STORE;
|
||
|
|
private static readonly QUEUE_STORE;
|
||
|
|
private static readonly SYNC_STATE_STORE;
|
||
|
|
private db;
|
||
|
|
private initialized;
|
||
|
|
/**
|
||
|
|
* Initialize and open the database
|
||
|
|
*/
|
||
|
|
initialize(): Promise<void>;
|
||
|
|
/**
|
||
|
|
* Check if database is initialized
|
||
|
|
*/
|
||
|
|
isInitialized(): boolean;
|
||
|
|
/**
|
||
|
|
* Ensure database is initialized
|
||
|
|
*/
|
||
|
|
private ensureDB;
|
||
|
|
/**
|
||
|
|
* Get a single event by ID
|
||
|
|
*/
|
||
|
|
getEvent(id: string): Promise<ICalendarEvent | null>;
|
||
|
|
/**
|
||
|
|
* Get all events
|
||
|
|
*/
|
||
|
|
getAllEvents(): Promise<ICalendarEvent[]>;
|
||
|
|
/**
|
||
|
|
* Save an event (create or update)
|
||
|
|
*/
|
||
|
|
saveEvent(event: ICalendarEvent): Promise<void>;
|
||
|
|
/**
|
||
|
|
* Delete an event
|
||
|
|
*/
|
||
|
|
deleteEvent(id: string): Promise<void>;
|
||
|
|
/**
|
||
|
|
* Add operation to queue
|
||
|
|
*/
|
||
|
|
addToQueue(operation: Omit<IQueueOperation, 'id'>): Promise<void>;
|
||
|
|
/**
|
||
|
|
* Get all queue operations (sorted by timestamp)
|
||
|
|
*/
|
||
|
|
getQueue(): Promise<IQueueOperation[]>;
|
||
|
|
/**
|
||
|
|
* Remove operation from queue
|
||
|
|
*/
|
||
|
|
removeFromQueue(id: string): Promise<void>;
|
||
|
|
/**
|
||
|
|
* Clear entire queue
|
||
|
|
*/
|
||
|
|
clearQueue(): Promise<void>;
|
||
|
|
/**
|
||
|
|
* Save sync state value
|
||
|
|
*/
|
||
|
|
setSyncState(key: string, value: any): Promise<void>;
|
||
|
|
/**
|
||
|
|
* Get sync state value
|
||
|
|
*/
|
||
|
|
getSyncState(key: string): Promise<any | null>;
|
||
|
|
/**
|
||
|
|
* Serialize event for IndexedDB storage (convert Dates to ISO strings)
|
||
|
|
*/
|
||
|
|
private serializeEvent;
|
||
|
|
/**
|
||
|
|
* Deserialize event from IndexedDB (convert ISO strings to Dates)
|
||
|
|
*/
|
||
|
|
private deserializeEvent;
|
||
|
|
/**
|
||
|
|
* Close database connection
|
||
|
|
*/
|
||
|
|
close(): void;
|
||
|
|
/**
|
||
|
|
* Delete entire database (for testing/reset)
|
||
|
|
*/
|
||
|
|
static deleteDatabase(): Promise<void>;
|
||
|
|
/**
|
||
|
|
* Seed IndexedDB with mock data if empty
|
||
|
|
*/
|
||
|
|
seedIfEmpty(mockDataUrl?: string): Promise<void>;
|
||
|
|
}
|