Fix some ts errors
This commit is contained in:
@@ -18,14 +18,14 @@ export type StorageAdapter = {
|
|||||||
options: StorageAdapterOptions
|
options: StorageAdapterOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
export let db: IDBPDatabase
|
export let db: IDBPDatabase | undefined
|
||||||
|
|
||||||
export const dead = withGetter(writable(false))
|
export const dead = withGetter(writable(false))
|
||||||
|
|
||||||
export const subs: Unsubscriber[] = []
|
export const subs: Unsubscriber[] = []
|
||||||
|
|
||||||
export const getAll = async (name: string) => {
|
export const getAll = async (name: string) => {
|
||||||
const tx = db.transaction(name, "readwrite")
|
const tx = db!.transaction(name, "readwrite")
|
||||||
const store = tx.objectStore(name)
|
const store = tx.objectStore(name)
|
||||||
const result = await store.getAll()
|
const result = await store.getAll()
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ export const getAll = async (name: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const bulkPut = async (name: string, data: any[]) => {
|
export const bulkPut = async (name: string, data: any[]) => {
|
||||||
const tx = db.transaction(name, "readwrite")
|
const tx = db!.transaction(name, "readwrite")
|
||||||
const store = tx.objectStore(name)
|
const store = tx.objectStore(name)
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
@@ -52,7 +52,7 @@ export const bulkPut = async (name: string, data: any[]) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const bulkDelete = async (name: string, ids: string[]) => {
|
export const bulkDelete = async (name: string, ids: string[]) => {
|
||||||
const tx = db.transaction(name, "readwrite")
|
const tx = db!.transaction(name, "readwrite")
|
||||||
const store = tx.objectStore(name)
|
const store = tx.objectStore(name)
|
||||||
|
|
||||||
await Promise.all(ids.map(id => store.delete(id)))
|
await Promise.all(ids.map(id => store.delete(id)))
|
||||||
@@ -139,9 +139,11 @@ export const closeStorage = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const clearStorage = async () => {
|
export const clearStorage = async () => {
|
||||||
|
if (db) {
|
||||||
await closeStorage()
|
await closeStorage()
|
||||||
await deleteDB(db.name)
|
await deleteDB(db.name)
|
||||||
db = undefined // force initStorage to run again
|
db = undefined // force initStorage to run again in tests
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const migrate = (data: any[], options: StorageAdapterOptions) =>
|
const migrate = (data: any[], options: StorageAdapterOptions) =>
|
||||||
|
|||||||
@@ -186,10 +186,10 @@ thunkWorker.addGlobalHandler((thunk: Thunk) => {
|
|||||||
// Avoid making this function async so multiple publishes can run concurrently
|
// Avoid making this function async so multiple publishes can run concurrently
|
||||||
Promise.resolve().then(async () => {
|
Promise.resolve().then(async () => {
|
||||||
const fail = (message: string) => {
|
const fail = (message: string) => {
|
||||||
const status = new Map<string, ThunkStatus>()
|
const status: ThunkStatusByUrl = {}
|
||||||
|
|
||||||
for (const url of thunk.request.relays) {
|
for (const url of thunk.request.relays) {
|
||||||
status.set(url, {status: PublishStatus.Failed, message})
|
status[url] = {status: PublishStatus.Failure, message}
|
||||||
}
|
}
|
||||||
|
|
||||||
thunk.status.set(status)
|
thunk.status.set(status)
|
||||||
@@ -207,7 +207,7 @@ thunkWorker.addGlobalHandler((thunk: Thunk) => {
|
|||||||
try {
|
try {
|
||||||
event = await signer.sign(event)
|
event = await signer.sign(event)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return fail(e.toString())
|
return fail(String(e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user