Fix IndexedDB in-line vs out-of-line key handling

- Check if store has keyPath before calling put()
- If keyPath exists (in-line keys), only pass value: store.put(value)
- If no keyPath (out-of-line keys), pass both: store.put(value, key)
- Apply fix to both set() and transaction.set()
- Fixes DataError when saving sessions with keyPath: 'id'
This commit is contained in:
Mario Zechner 2025-10-08 16:53:54 +02:00
parent 0de89a750e
commit db34ef01bf

View file

@ -64,7 +64,13 @@ export class IndexedDBStorageBackend implements StorageBackend {
const db = await this.getDB();
const tx = db.transaction(storeName, "readwrite");
const store = tx.objectStore(storeName);
await this.promisifyRequest(store.put(value, key));
// If store has keyPath, only pass value (in-line key)
// Otherwise pass both value and key (out-of-line key)
if (store.keyPath) {
await this.promisifyRequest(store.put(value));
} else {
await this.promisifyRequest(store.put(value, key));
}
}
async delete(storeName: string, key: string): Promise<void> {
@ -121,7 +127,13 @@ export class IndexedDBStorageBackend implements StorageBackend {
},
set: async <T>(storeName: string, key: string, value: T) => {
const store = idbTx.objectStore(storeName);
await this.promisifyRequest(store.put(value, key));
// If store has keyPath, only pass value (in-line key)
// Otherwise pass both value and key (out-of-line key)
if (store.keyPath) {
await this.promisifyRequest(store.put(value));
} else {
await this.promisifyRequest(store.put(value, key));
}
},
delete: async (storeName: string, key: string) => {
const store = idbTx.objectStore(storeName);