Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/objectstoreprovider",
"version": "0.8.0",
"version": "0.8.1",
"description": "A cross-browser object store library",
"author": "Mukundan Kavanur Kidambi <[email protected]>",
"scripts": {
Expand Down
15 changes: 14 additions & 1 deletion src/InMemoryProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ class InMemoryIndex extends DbIndexFTSFromRangeQueries {
const iterator = this._indexTree.entries();
const keys = [];
for (const entry of iterator) {
const key = entry.key;
let key = entry.key;
if (key === undefined) {
continue;
}
Expand All @@ -929,9 +929,22 @@ class InMemoryIndex extends DbIndexFTSFromRangeQueries {
(key > keyLow || (key === keyLow && !lowRangeExclusive)) &&
(key < keyHigh || (key === keyHigh && !highRangeExclusive))
) {
if (this._keyPath !== this._primaryKeyPath) {
key =
getSerializedKeyForKeypath(
entry.value?.[0],
this._primaryKeyPath
) ?? key;
if (key === entry.key) {
this.logger.warn(
`getSerializedKeyForKeypath returned undefined key in InMemoryIndex for table: ${this.tableName}, with index: ${this._indexSchema?.name}`
);
}
}
keys.push(key);
}
}

return keys;
}

Expand Down
65 changes: 65 additions & 0 deletions src/tests/ObjectStoreProvider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1886,6 +1886,71 @@ describe("ObjectStoreProvider", function () {
);
});

it("Remove range (all removed with index)", (done) => {
// Not working with index, need to be fix in the future.
if (provName === "indexeddbfakekeys") {
done();
return;
}

openProvider(
provName,
{
version: 1,
stores: [
{
name: "test",
primaryKeyPath: "id",
indexes: [
{
name: "index",
keyPath: "a",
},
],
},
],
},
true
)
.then((prov) => {
return prov
.put(
"test",
[1, 2, 3, 4, 5].map((i) => {
return { id: "a" + i, a: "index_value_a_" + i };
})
)
.then(() => {
return prov.getAll("test", undefined).then((rets) => {
assert(!!rets);
assert.equal(rets.length, 5);
return prov
.removeRange(
"test",
"index",
"index_value_a_1",
"index_value_a_5"
)
.then(() => {
return prov
.getAll("test", undefined)
.then((retVals) => {
const rets = retVals as TestObj[];
assert(!!rets);
assert.equal(rets.length, 0);
});
});
});
})
.then(() => prov.close())
.catch((e) => prov.close().then(() => Promise.reject(e)));
})
.then(
() => done(),
(err) => done(err)
);
});

it("Invalid Key Type", (done) => {
openProvider(
provName,
Expand Down