summaryrefslogtreecommitdiff
path: root/packages/idb-bridge/src/util/makeStoreKeyValue.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-06-21 19:18:36 +0200
committerFlorian Dold <florian.dold@gmail.com>2019-06-21 19:18:36 +0200
commita4e4125cca8644703d7cff527a39c1a5a9842eba (patch)
treefb4de931ea0db1f314fcf6850806989a40c9e76e /packages/idb-bridge/src/util/makeStoreKeyValue.ts
parent2ee9431f1ba5bf67546bbf85758a01991c40673f (diff)
downloadwallet-core-a4e4125cca8644703d7cff527a39c1a5a9842eba.tar.gz
wallet-core-a4e4125cca8644703d7cff527a39c1a5a9842eba.tar.bz2
wallet-core-a4e4125cca8644703d7cff527a39c1a5a9842eba.zip
idb: tests working
Diffstat (limited to 'packages/idb-bridge/src/util/makeStoreKeyValue.ts')
-rw-r--r--packages/idb-bridge/src/util/makeStoreKeyValue.ts24
1 files changed, 18 insertions, 6 deletions
diff --git a/packages/idb-bridge/src/util/makeStoreKeyValue.ts b/packages/idb-bridge/src/util/makeStoreKeyValue.ts
index 4850cec26..4f45e0d8a 100644
--- a/packages/idb-bridge/src/util/makeStoreKeyValue.ts
+++ b/packages/idb-bridge/src/util/makeStoreKeyValue.ts
@@ -63,10 +63,14 @@ export function makeStoreKeyValue(
updatedKeyGenerator = currentKeyGenerator + 1;
} else if (typeof maybeInlineKey === "number") {
key = maybeInlineKey;
- updatedKeyGenerator = maybeInlineKey;
+ if (maybeInlineKey >= currentKeyGenerator) {
+ updatedKeyGenerator = maybeInlineKey + 1;
+ } else {
+ updatedKeyGenerator = currentKeyGenerator;
+ }
} else {
key = maybeInlineKey;
- updatedKeyGenerator = currentKeyGenerator + 1;
+ updatedKeyGenerator = currentKeyGenerator;
}
return {
key: key,
@@ -84,9 +88,17 @@ export function makeStoreKeyValue(
};
}
} else {
- // (no, no, yes)
- // (no, no, no)
- throw new DataError();
+ if (autoIncrement) {
+ // (no, no, yes)
+ return {
+ key: currentKeyGenerator,
+ value: value,
+ updatedKeyGenerator: currentKeyGenerator + 1,
+ }
+ } else {
+ // (no, no, no)
+ throw new DataError();
+ }
}
}
-} \ No newline at end of file
+}