Skip to content

Commit 6c86a80

Browse files
committed
Test and fix remove nested
1 parent 275cf48 commit 6c86a80

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/nested.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ const Nested =
7272
};
7373

7474
const del = async (key: NestedKey): Promise<string> => {
75-
return addOperation({ op: "DEL", key, value: null });
75+
const joinedKey = typeof key === "string" ? key : joinKey(key);
76+
return addOperation({ op: "DEL", key: joinedKey, value: null });
7677
};
7778

7879
const get = async (key: NestedKey): Promise<PossiblyNestedValue> => {
@@ -165,6 +166,7 @@ const Nested =
165166
put,
166167
set: put,
167168
putNested,
169+
settNested: putNested,
168170
get,
169171
del,
170172
iterator,

test/nested.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,17 @@ describe("Nested Database", () => {
183183
expect(actualAB).to.equal(1);
184184
});
185185

186+
it("remove a nested value", async () => {
187+
await db.put(["a/b"], 1);
188+
await db.put("a/c", 2);
189+
190+
await db.del("a/b")
191+
await db.del(["a", "c"])
192+
193+
const actual = await db.all();
194+
expect(actual).to.be.empty();
195+
});
196+
186197
it("add a nested value - list syntax", async () => {
187198
const hash1 = await db.put(["a", "b"], 1);
188199
const hash2 = await db.put(["a", "c"], 2);

0 commit comments

Comments
 (0)