From 41d4a0cd8f1ddfac6a7e21ecd17e173469a6aeb8 Mon Sep 17 00:00:00 2001 From: Jack Case Date: Wed, 7 Jan 2026 21:22:43 +0000 Subject: [PATCH] implemented SlopStore and tested --- spec/indexeddb_spec.js | 23 +++++++++++++++++++++-- src/indexed-db.ts | 20 ++++++++++++++++---- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/spec/indexeddb_spec.js b/spec/indexeddb_spec.js index b327f09..f2ab241 100644 --- a/spec/indexeddb_spec.js +++ b/spec/indexeddb_spec.js @@ -153,7 +153,26 @@ describe("SlopStore", () => { db.close() }) - it("passes", () => { - expect(true).toBeTrue() + it("stores slop", async () => { + const stored = await slopdb.slop_store.store("its-slop.slop", "some/slop") + expect(stored).toBe("its-slop.slop") + + const retrieved = await slopdb.slop_store.get(new URL("http://its-slop.slop/some/slop")) + const expected_set = new Set() + expected_set.add("some/slop") + expect(retrieved).toEqual({domain: "its-slop.slop", paths: expected_set}) + }) + + it("stores new slop paths to existing domains", async () => { + const stored = await slopdb.slop_store.store("its-slop.slop", "some/slop") + const new_path = await slopdb.slop_store.store("its-slop.slop", "some/other/slop") + expect(new_path).toBe("its-slop.slop") + + const expected_set = new Set() + expected_set.add("some/slop") + expected_set.add("some/other/slop") + + const retrieved = await slopdb.slop_store.get(new URL("http://its-slop.slop/some/slop")) + expect(retrieved).toEqual({domain: "its-slop.slop", paths: expected_set}) }) }) diff --git a/src/indexed-db.ts b/src/indexed-db.ts index 2242681..5a25c33 100644 --- a/src/indexed-db.ts +++ b/src/indexed-db.ts @@ -56,12 +56,24 @@ export class SlopStore { this.slopdb = slopdb } - async store(domain: string, path: string) { - + async store(domain: string, path: string): Promise { + const slop_store = this.slopdb.transaction(SlopStore.slop_objectstore_name, "readwrite").objectStore(SlopStore.slop_objectstore_name) + const existing_domain = await slop_store.get(domain) + if(existing_domain) { + // append this path to the existing domain object + existing_domain.paths.add(path) + return slop_store.put(existing_domain) + } else { + // create a domain object containing this path + const paths_set = new Set() + paths_set.add(path) + return slop_store.add({domain: domain, paths: paths_set}) + } } - async get(url: string) { - + async get(url: URL) { + const slop_store = this.slopdb.transaction(SlopStore.slop_objectstore_name, "readonly").objectStore(SlopStore.slop_objectstore_name) + return await slop_store.get(url.hostname) } }