From dbe14c9b25cd08168f956052e557fd13e8ed0835 Mon Sep 17 00:00:00 2001 From: Jack Case Date: Wed, 10 Dec 2025 20:15:50 +0000 Subject: [PATCH] switch to a library with ts support out of the box, idb --- dev-scripts/build-extension.sh | 4 ++-- package.json | 4 ++-- spec/indexeddb_spec.mjs | 9 --------- src/@custom_types/indexeddb.d.ts | 3 +++ src/indexed-db.mts | 17 ++++++++++------- tsconfig.json | 4 ++-- yarn.lock | 9 +++++---- 7 files changed, 24 insertions(+), 26 deletions(-) create mode 100644 src/@custom_types/indexeddb.d.ts diff --git a/dev-scripts/build-extension.sh b/dev-scripts/build-extension.sh index 5f8fe02..a02761b 100755 --- a/dev-scripts/build-extension.sh +++ b/dev-scripts/build-extension.sh @@ -8,8 +8,8 @@ if tsc; then cp -r node_modules/altcha/dist_external scripts/altcha/ cp node_modules/altcha/* scripts/altcha/ - mkdir -p scripts/indexeddb-promise - cp node_modules/@coderundebug/indexeddb-promise/* scripts/indexeddb-promise + mkdir -p scripts/idb + cp node_modules/idb/build/* scripts/idb/ zip -r package.zip icons/ pages/ scripts/ styles/ manifest.json diff --git a/package.json b/package.json index 5e4b1ec..5c47eff 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "dependencies": { - "@coderundebug/indexeddb-promise": "git+https://github.com/StephenHassall/indexeddb-promise.git", - "altcha": "^2.2.4" + "altcha": "^2.2.4", + "idb": "^8.0.3" }, "devDependencies": { "@types/firefox-webext-browser": "^143.0.0", diff --git a/spec/indexeddb_spec.mjs b/spec/indexeddb_spec.mjs index 6bc0ee5..4596c15 100644 --- a/spec/indexeddb_spec.mjs +++ b/spec/indexeddb_spec.mjs @@ -21,16 +21,7 @@ describe("SlopDB Version 1", () => { it("creates a version 1 indexeddb", async () => { const slopdb_v1 = new SlopDB(1) - await slopdb_v1.db_opened() - expect(slopdb_v1.db).toBeDefined() - const transaction = slopdb_v1.start_transaction("slop", "readonly") - expect(transaction).toBeDefined() - try { - const bad_transaction = slopdb_v1.start_transaction("checkcache", "readonly") - } catch (error) { - expect(error.name).toBe("NotFoundError") - } }) }) \ No newline at end of file diff --git a/src/@custom_types/indexeddb.d.ts b/src/@custom_types/indexeddb.d.ts new file mode 100644 index 0000000..faebd30 --- /dev/null +++ b/src/@custom_types/indexeddb.d.ts @@ -0,0 +1,3 @@ +declare class Database { + constructor(name: string, version: number) +} \ No newline at end of file diff --git a/src/indexed-db.mts b/src/indexed-db.mts index dd68790..e51b50f 100644 --- a/src/indexed-db.mts +++ b/src/indexed-db.mts @@ -1,7 +1,4 @@ -// import { } from "./common.js" -import { Database } from "indexeddb-promise/indexeddb.js" - -const db = new Database("asdf", 1) +import { openDB, IDBPDatabase } from "/idb/index.js" export class IDBCursorValueIterator { cursor: IDBCursorWithValue @@ -39,11 +36,17 @@ export class IDBCursorValueIterator { export class SlopDB { - open_promise: Promise - db: IDBDatabase + version: number + open_promise: Promise + db: IDBPDatabase constructor(idb_version: number) { - this.open_promise = this.open_database(idb_version) + this.version = idb_version + this.open_promise = openDB("SlopDB", idb_version, { + upgrade(db, oldVersion, newVersion, transaction, event) { + //TODO + } + }) } async db_opened() { diff --git a/tsconfig.json b/tsconfig.json index f2ceb90..a30b215 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,7 @@ "compilerOptions": { "allowJs": true, "outDir": "scripts", - "lib": ["ES7", "DOM"], + "lib": ["ESNext", "DOM"], // "noImplicitAny": true, "noFallthroughCasesInSwitch": true, @@ -18,7 +18,7 @@ "target": "esnext", "baseUrl": ".", "paths": { - "indexeddb-promise/*": ["node_modules/@coderundebug/indexeddb-promise/*"] + "/idb/*": ["node_modules/idb/build/*"] }, "module": "nodenext", diff --git a/yarn.lock b/yarn.lock index 425eb5d..a30259f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12,10 +12,6 @@ resolved "https://registry.yarnpkg.com/@bazel/runfiles/-/runfiles-6.5.0.tgz#63cf7b77b91b54873e75f7a08fabec215c6888be" integrity sha512-RzahvqTkfpY2jsDxo8YItPX+/iZ6hbiikw1YhE0bA9EKBR5Og8Pa6FHn9PO9M0zaXRVsr0GFQLKbB/0rzy9SzA== -"@coderundebug/indexeddb-promise@git+https://github.com/StephenHassall/indexeddb-promise.git": - version "1.0.4" - resolved "git+https://github.com/StephenHassall/indexeddb-promise.git#5b7427145f60215eaa533fd15218736fc203a068" - "@isaacs/cliui@^8.0.2": version "8.0.2" resolved "https://registry.yarnpkg.com/@isaacs/cliui/-/cliui-8.0.2.tgz#b37667b7bc181c168782259bab42474fbf52b550" @@ -408,6 +404,11 @@ iconv-lite@^0.7.0, iconv-lite@~0.7.0: dependencies: safer-buffer ">= 2.1.2 < 3.0.0" +idb@^8.0.3: + version "8.0.3" + resolved "https://registry.yarnpkg.com/idb/-/idb-8.0.3.tgz#c91e558f15a8d53f1d7f53a094d226fc3ad71fd9" + integrity sha512-LtwtVyVYO5BqRvcsKuB2iUMnHwPVByPCXFXOpuU96IZPPoPN6xjOGxZQ74pgSVVLQWtUOYgyeL4GE98BY5D3wg== + immediate@~3.0.5: version "3.0.6" resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.0.6.tgz#9db1dbd0faf8de6fbe0f5dd5e56bb606280de69b"