diff options
author | Özgür Kesim <oec-taler@kesim.org> | 2023-08-25 13:24:08 +0200 |
---|---|---|
committer | Özgür Kesim <oec-taler@kesim.org> | 2023-08-25 13:24:08 +0200 |
commit | 5ab3070b3a63c2e8fed0e413dea06cf03fb48f1e (patch) | |
tree | 121425d99c9465f2daf8ac91c6dc2254ebac5906 /packages/idb-bridge/src/util/makeStoreKeyValue.ts | |
parent | 70fca92e781696a057089bc8bc48adebdf6e017e (diff) | |
parent | 2051aded501cddac1a4c869fb1f9731ac4523a1e (diff) |
Merge branch 'master' into age-withdraw
Diffstat (limited to 'packages/idb-bridge/src/util/makeStoreKeyValue.ts')
-rw-r--r-- | packages/idb-bridge/src/util/makeStoreKeyValue.ts | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/packages/idb-bridge/src/util/makeStoreKeyValue.ts b/packages/idb-bridge/src/util/makeStoreKeyValue.ts index 4c7dab8d2..153cd9d81 100644 --- a/packages/idb-bridge/src/util/makeStoreKeyValue.ts +++ b/packages/idb-bridge/src/util/makeStoreKeyValue.ts @@ -75,19 +75,25 @@ function injectKey( return newValue; } -export function makeStoreKeyValue( - value: any, - key: IDBValidKey | undefined, - currentKeyGenerator: number, - autoIncrement: boolean, - keyPath: IDBKeyPath | IDBKeyPath[] | null, -): StoreKeyResult { +export interface MakeStoreKvRequest { + value: any; + key: IDBValidKey | undefined; + currentKeyGenerator: number; + autoIncrement: boolean; + keyPath: IDBKeyPath | IDBKeyPath[] | null; +} + +export function makeStoreKeyValue(req: MakeStoreKvRequest): StoreKeyResult { + const { keyPath, currentKeyGenerator, autoIncrement } = req; + let { key, value } = req; + const haveKey = key !== null && key !== undefined; const haveKeyPath = keyPath !== null && keyPath !== undefined; // This models a decision table on (haveKey, haveKeyPath, autoIncrement) try { + // FIXME: Perf: only do this if we need to inject something. value = structuredClone(value); } catch (e) { throw new DataCloneError(); |