aboutsummaryrefslogtreecommitdiff
path: root/packages/idb-bridge/src/util/getIndexKeys.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/getIndexKeys.ts
parent2ee9431f1ba5bf67546bbf85758a01991c40673f (diff)
downloadwallet-core-a4e4125cca8644703d7cff527a39c1a5a9842eba.tar.xz
idb: tests working
Diffstat (limited to 'packages/idb-bridge/src/util/getIndexKeys.ts')
-rw-r--r--packages/idb-bridge/src/util/getIndexKeys.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/packages/idb-bridge/src/util/getIndexKeys.ts b/packages/idb-bridge/src/util/getIndexKeys.ts
new file mode 100644
index 000000000..416cf9ea2
--- /dev/null
+++ b/packages/idb-bridge/src/util/getIndexKeys.ts
@@ -0,0 +1,28 @@
+import { Key, Value, KeyPath } from "./types";
+import extractKey from "./extractKey";
+import valueToKey from "./valueToKey";
+
+export function getIndexKeys(
+ value: Value,
+ keyPath: KeyPath,
+ multiEntry: boolean,
+): Key[] {
+ if (multiEntry && Array.isArray(keyPath)) {
+ const keys = [];
+ for (const subkeyPath of keyPath) {
+ const key = extractKey(subkeyPath, value);
+ try {
+ const k = valueToKey(key);
+ keys.push(k);
+ } catch {
+ // Ignore invalid subkeys
+ }
+ }
+ return keys;
+ } else {
+ let key = extractKey(keyPath, value);
+ return [valueToKey(key)];
+ }
+}
+
+export default getIndexKeys;