create skeleton SlopStore class for operations on the slop object store

This commit is contained in:
Jack Case
2026-01-05 19:17:08 +00:00
parent ab29ecd3ae
commit 0f1ea5fc31

View File

@@ -1,39 +1,5 @@
import { openDB, IDBPDatabase, unwrap } from "idb/index.js"
export class IDBCursorValueIterator {
cursor: IDBCursorWithValue
constructor(cursor: IDBCursorWithValue) {
this.cursor = cursor
}
next(): IteratorResult<any> {
const key = this.cursor.key
const value = this.cursor.value
let done = false
try {
this.cursor.continue()
}
catch (error) {
if (error.name === "InvalidStateError") {
done = true
}
else {
throw error
}
}
finally {
return { value: {key: key, value: value}, done: done }
}
}
[Symbol.iterator]() {
return this
}
}
export class CheckCache {
slopdb: IDBPDatabase
cache_capacity: number
@@ -82,13 +48,22 @@ export class CheckCache {
}
}
export class SlopStore {
slopdb: IDBPDatabase
static slop_objectstore_name = "slop"
constructor(slopdb: IDBPDatabase) {
this.slopdb = slopdb
}
}
export class SlopDB {
version: number
open_promise: Promise<any>
db: IDBPDatabase
// slop_store: SlopStore
check_cache: CheckCache
slop_store: SlopStore
static apply_db_upgrade(db: IDBPDatabase, idb_version: number) {
switch (idb_version) {
@@ -121,6 +96,9 @@ export class SlopDB {
this.db = db
// create a CheckCache object to handle the check_cache object store
this.check_cache = new CheckCache(this.db, 512)
// create a SlopStore object to handle the slop object store
this.slop_store = new SlopStore(this.db)
})
}