Skip to content

Commit 00794bc

Browse files
dawsontothkriszyp
authored andcommitted
fix: Return consistent values from getIndexedValues
The `return values.push` would return integers or null directly.
1 parent 971bac7 commit 00794bc

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

utility/lmdb/commonUtility.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,28 +58,39 @@ function convertKeyValueToWrite(key) {
5858
* Return all the indexable values from an attribute, ready to be indexed
5959
*/
6060
function getIndexedValues(value, indexNulls) {
61-
if (value === null) return indexNulls ? [null] : undefined;
62-
if (value === undefined) return;
61+
if (value === null) {
62+
return indexNulls ? [null] : undefined;
63+
}
64+
if (value === undefined) {
65+
return undefined;
66+
}
6367
if (PRIMITIVES.includes(typeof value)) {
6468
if (value.length > MAX_SEARCH_KEY_LENGTH) {
6569
return [value.slice(0, MAX_SEARCH_KEY_LENGTH) + OVERFLOW_MARKER];
6670
}
6771
return [value];
6872
}
69-
let values;
7073
if (Array.isArray(value)) {
71-
values = [];
74+
const values = [];
7275
for (let i = 0, l = value.length; i < l; i++) {
7376
let element = value[i];
7477
if (PRIMITIVES.includes(typeof element)) {
75-
if (element.length > MAX_SEARCH_KEY_LENGTH)
78+
if (element.length > MAX_SEARCH_KEY_LENGTH) {
7679
values.push(element.slice(0, MAX_SEARCH_KEY_LENGTH) + OVERFLOW_MARKER);
77-
else values.push(element);
78-
} else if (element === null && indexNulls) return values.push(null);
79-
else if (element instanceof Date) return values.push(element.getTime());
80+
} else {
81+
values.push(element);
82+
}
83+
} else if (element === null && indexNulls) {
84+
values.push(null);
85+
} else if (element instanceof Date) {
86+
values.push(element.getTime());
87+
}
8088
}
81-
} else if (value instanceof Date) return [value.getTime()];
82-
return values;
89+
return values;
90+
} else if (value instanceof Date) {
91+
return [value.getTime()];
92+
}
93+
return undefined;
8394
}
8495

8596
let lastTime = 0; // reported time used to ensure monotonic time.

0 commit comments

Comments
 (0)