diff options
author | Florian Dold <florian@dold.me> | 2023-07-11 15:41:48 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-08-22 08:01:13 +0200 |
commit | b2d0ad57ddf251a109d536cdc49fb6505dbdc50c (patch) | |
tree | 7eaeca3ad8ec97a9c1970c1004feda2d61c3441b /packages/idb-bridge/src/util/makeStoreKeyValue.ts | |
parent | 58fdf9dc091b076787a9746c405fe6a9366f5da6 (diff) | |
download | wallet-core-b2d0ad57ddf251a109d536cdc49fb6505dbdc50c.tar.gz wallet-core-b2d0ad57ddf251a109d536cdc49fb6505dbdc50c.tar.bz2 wallet-core-b2d0ad57ddf251a109d536cdc49fb6505dbdc50c.zip |
sqlite3 backend for idb-bridge / wallet-core
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(); |