switch to a library with ts support out of the box, idb
This commit is contained in:
@@ -8,8 +8,8 @@ if tsc; then
|
|||||||
cp -r node_modules/altcha/dist_external scripts/altcha/
|
cp -r node_modules/altcha/dist_external scripts/altcha/
|
||||||
cp node_modules/altcha/* scripts/altcha/
|
cp node_modules/altcha/* scripts/altcha/
|
||||||
|
|
||||||
mkdir -p scripts/indexeddb-promise
|
mkdir -p scripts/idb
|
||||||
cp node_modules/@coderundebug/indexeddb-promise/* scripts/indexeddb-promise
|
cp node_modules/idb/build/* scripts/idb/
|
||||||
|
|
||||||
zip -r package.zip icons/ pages/ scripts/ styles/ manifest.json
|
zip -r package.zip icons/ pages/ scripts/ styles/ manifest.json
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"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": {
|
"devDependencies": {
|
||||||
"@types/firefox-webext-browser": "^143.0.0",
|
"@types/firefox-webext-browser": "^143.0.0",
|
||||||
|
|||||||
@@ -21,16 +21,7 @@ describe("SlopDB Version 1", () => {
|
|||||||
|
|
||||||
it("creates a version 1 indexeddb", async () => {
|
it("creates a version 1 indexeddb", async () => {
|
||||||
const slopdb_v1 = new SlopDB(1)
|
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")
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
3
src/@custom_types/indexeddb.d.ts
vendored
Normal file
3
src/@custom_types/indexeddb.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
declare class Database {
|
||||||
|
constructor(name: string, version: number)
|
||||||
|
}
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
// import { } from "./common.js"
|
import { openDB, IDBPDatabase } from "/idb/index.js"
|
||||||
import { Database } from "indexeddb-promise/indexeddb.js"
|
|
||||||
|
|
||||||
const db = new Database("asdf", 1)
|
|
||||||
|
|
||||||
export class IDBCursorValueIterator {
|
export class IDBCursorValueIterator {
|
||||||
cursor: IDBCursorWithValue
|
cursor: IDBCursorWithValue
|
||||||
@@ -39,11 +36,17 @@ export class IDBCursorValueIterator {
|
|||||||
|
|
||||||
|
|
||||||
export class SlopDB {
|
export class SlopDB {
|
||||||
open_promise: Promise<IDBDatabase>
|
version: number
|
||||||
db: IDBDatabase
|
open_promise: Promise<IDBPDatabase>
|
||||||
|
db: IDBPDatabase
|
||||||
|
|
||||||
constructor(idb_version: number) {
|
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() {
|
async db_opened() {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"outDir": "scripts",
|
"outDir": "scripts",
|
||||||
"lib": ["ES7", "DOM"],
|
"lib": ["ESNext", "DOM"],
|
||||||
|
|
||||||
// "noImplicitAny": true,
|
// "noImplicitAny": true,
|
||||||
"noFallthroughCasesInSwitch": true,
|
"noFallthroughCasesInSwitch": true,
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
"target": "esnext",
|
"target": "esnext",
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"indexeddb-promise/*": ["node_modules/@coderundebug/indexeddb-promise/*"]
|
"/idb/*": ["node_modules/idb/build/*"]
|
||||||
},
|
},
|
||||||
"module": "nodenext",
|
"module": "nodenext",
|
||||||
|
|
||||||
|
|||||||
@@ -12,10 +12,6 @@
|
|||||||
resolved "https://registry.yarnpkg.com/@bazel/runfiles/-/runfiles-6.5.0.tgz#63cf7b77b91b54873e75f7a08fabec215c6888be"
|
resolved "https://registry.yarnpkg.com/@bazel/runfiles/-/runfiles-6.5.0.tgz#63cf7b77b91b54873e75f7a08fabec215c6888be"
|
||||||
integrity sha512-RzahvqTkfpY2jsDxo8YItPX+/iZ6hbiikw1YhE0bA9EKBR5Og8Pa6FHn9PO9M0zaXRVsr0GFQLKbB/0rzy9SzA==
|
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":
|
"@isaacs/cliui@^8.0.2":
|
||||||
version "8.0.2"
|
version "8.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/@isaacs/cliui/-/cliui-8.0.2.tgz#b37667b7bc181c168782259bab42474fbf52b550"
|
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:
|
dependencies:
|
||||||
safer-buffer ">= 2.1.2 < 3.0.0"
|
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:
|
immediate@~3.0.5:
|
||||||
version "3.0.6"
|
version "3.0.6"
|
||||||
resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.0.6.tgz#9db1dbd0faf8de6fbe0f5dd5e56bb606280de69b"
|
resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.0.6.tgz#9db1dbd0faf8de6fbe0f5dd5e56bb606280de69b"
|
||||||
|
|||||||
Reference in New Issue
Block a user