Client API
IndexedDbStorage Class
Main client-side storage interface for chat operations.
Import
import { indexedDbStorage } from './src/services/indexedDbStorage';Initialization
The storage is automatically initialized on module load. Check readiness:
import { ready } from './src/services/indexedDbStorage';
await ready; // Ensures database is initializedCore Methods
saveConversation(conversation: Chat): Promise
Save or update a conversation.
await indexedDbStorage.saveConversation({
id: 'chat-123',
title: 'My Chat',
messages: [
{
id: 'msg-1',
role: 'user',
content: 'Hello',
timestamp: new Date()
}
],
createdAt: new Date(),
updatedAt: new Date(),
lastModified: new Date(),
model: 'gpt-4',
provider: 'openai',
isArchived: false
});listConversations(showArchived?: boolean): Promise<Chat[]>
Get all conversations, optionally including archived ones.
Returns conversations ordered by lastModified (newest first).
loadConversation(id: string): Promise
Load a specific conversation by ID.
Throws error if conversation not found.
deleteConversation(id: string): Promise
Permanently delete a conversation.
Legacy Methods (Compatibility)
getChats(): Promise<Chat[]>
Alias for listConversations().
getChat(id: string): Promise<Chat | null>
Get conversation by ID, returns null if not found.
saveChat(chat: Chat): Promise
Save chat and return the chat ID.
deleteChat(id: string): Promise
Alias for deleteConversation().
Utility Methods
initialize(): Promise
Manually initialize the database (usually not needed).
isReady(): Promise
Check if database is ready for operations.
migrateFromLocalStorage(): Promise
Migrate data from localStorage to IndexedDB (automatic on first load).
Metadata Operations
getMeta(id?: string): Promise<AppMeta | null>
Get application metadata.
setMeta(meta: AppMeta): Promise
Set application metadata.
Error Handling
All methods handle errors gracefully:
Database initialization failures trigger automatic recovery
Missing data returns null/empty arrays rather than throwing
Date conversion errors fall back to current timestamp
Quota exceeded errors log warnings but don't throw
Data Persistence
Storage: Browser IndexedDB via Dexie ORM
Database Name:
PolyglotDBTables:
chats,metaPersistence: Survives browser restarts, tab closes
Capacity: ~50MB typical, varies by browser
Date Handling
All date fields are automatically converted:
Storage: Dates stored as ISO strings
Retrieval: Automatically converted back to Date objects
Fallback: Invalid dates default to current timestamp
Browser Compatibility
Chrome 61+: Full support
Firefox 60+: Full support
Safari 13.1+: Full support
Edge 79+: Full support
IE: Not supported
Last updated