Skip to content

Commit

Permalink
Formatting and type fix
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed Jun 3, 2024
1 parent cc5fe4e commit cde51d7
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/IndexedDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,27 @@ function wrap<T>(request: IDBRequest<T>): Promise<T> {
/**
* @hidden
*/
export class IndexedDBTransaction extends AsyncTransaction {
export class IndexedDBTransaction extends AsyncTransaction<IndexedDBStore> {
private _idb: IDBObjectStore;

constructor(
public tx: IDBTransaction,
public store: IDBObjectStore
public store: IndexedDBStore
) {
super();
super(store);
this._idb = tx.objectStore(store.name);
}

public get(key: Ino): Promise<Uint8Array> {
return wrap(this.store.get(key.toString()));
return wrap(this._idb.get(key.toString()));
}

public async set(key: Ino, data: Uint8Array): Promise<void> {
await wrap(this.store.put(data, key.toString()));
await wrap(this._idb.put(data, key.toString()));
}

public remove(key: Ino): Promise<void> {
return wrap(this.store.delete(key.toString()));
return wrap(this._idb.delete(key.toString()));
}

public async commit(): Promise<void> {
Expand Down Expand Up @@ -74,20 +77,20 @@ export class IndexedDBStore implements Store {
}

public get name(): string {
return IndexedDB.name + ':' + this.db.name;
return this.db.name;
}

public clear(): Promise<void> {
return wrap(this.db.transaction(this.db.name, 'readwrite').objectStore(this.db.name).clear());
return wrap(this.db.transaction(this.name, 'readwrite').objectStore(this.name).clear());
}

public clearSync(): void {
throw ErrnoError.With('ENOSYS', undefined, 'IndexedDBStore.clearSync');
}

public transaction(): IndexedDBTransaction {
const tx = this.db.transaction(this.db.name, 'readwrite');
return new IndexedDBTransaction(tx, tx.objectStore(this.db.name));
const tx = this.db.transaction(this.name, 'readwrite');
return new IndexedDBTransaction(tx, this);
}
}

Expand Down Expand Up @@ -145,7 +148,7 @@ export const IndexedDB = {
const db = await createDB(options.storeName || 'zenfs', options.idbFactory);
const store = new IndexedDBStore(db);
const fs = new (Async(StoreFS))(store);
if(!options?.disableAsyncCache) {
if (!options?.disableAsyncCache) {
fs._sync = InMemory.create({ name: 'idb-cache' });
}
return fs;
Expand Down

0 comments on commit cde51d7

Please sign in to comment.