Refactor storage architecture with modular IndexedDB services
Implements a more flexible, modular approach to IndexedDB storage: - Introduces IStore interface for dynamic store creation - Adds specialized services for each entity (BookingService, CustomerService, etc.) - Moves serialization logic to entity-specific classes - Improves dependency injection and extensibility Enables easier addition of new entity types with minimal configuration
This commit is contained in:
parent
88cccb3456
commit
2aa9d06fab
13 changed files with 1048 additions and 236 deletions
47
src/storage/events/EventStore.ts
Normal file
47
src/storage/events/EventStore.ts
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import { IStore } from '../IStore';
|
||||
|
||||
/**
|
||||
* EventStore - IndexedDB ObjectStore definition for calendar events
|
||||
*
|
||||
* Defines schema, indexes, and store creation logic.
|
||||
* Part of modular storage architecture where each entity has its own folder.
|
||||
*/
|
||||
export class EventStore implements IStore {
|
||||
/** ObjectStore name in IndexedDB (static for backward compatibility) */
|
||||
static readonly STORE_NAME = 'events';
|
||||
|
||||
/** ObjectStore name in IndexedDB (instance property for IStore interface) */
|
||||
readonly storeName = EventStore.STORE_NAME;
|
||||
|
||||
/**
|
||||
* Create the events ObjectStore with indexes
|
||||
* Called during database upgrade (onupgradeneeded)
|
||||
*
|
||||
* @param db - IDBDatabase instance
|
||||
*/
|
||||
create(db: IDBDatabase): void {
|
||||
// Create ObjectStore with 'id' as keyPath
|
||||
const store = db.createObjectStore(EventStore.STORE_NAME, { keyPath: 'id' });
|
||||
|
||||
// Index: start (for date range queries)
|
||||
store.createIndex('start', 'start', { unique: false });
|
||||
|
||||
// Index: end (for date range queries)
|
||||
store.createIndex('end', 'end', { unique: false });
|
||||
|
||||
// Index: syncStatus (for filtering by sync state)
|
||||
store.createIndex('syncStatus', 'syncStatus', { unique: false });
|
||||
|
||||
// Index: resourceId (CRITICAL for resource-mode filtering)
|
||||
store.createIndex('resourceId', 'resourceId', { unique: false });
|
||||
|
||||
// Index: customerId (for customer-centric queries)
|
||||
store.createIndex('customerId', 'customerId', { unique: false });
|
||||
|
||||
// Index: bookingId (for event-to-booking lookups)
|
||||
store.createIndex('bookingId', 'bookingId', { unique: false });
|
||||
|
||||
// Compound index: startEnd (for optimized range queries)
|
||||
store.createIndex('startEnd', ['start', 'end'], { unique: false });
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue