mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 18:01:22 +00:00
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:
parent
0de89a750e
commit
db34ef01bf
1 changed files with 14 additions and 2 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue