@atproto/oauth-client-browser
Version:
ATPROTO OAuth client for the browser (relies on WebCrypto & Indexed DB)
45 lines • 1.18 kB
JavaScript
import 'core-js/es/symbol/dispose.js';
import { DBObjectStore } from './db-object-store.js';
export class DBTransaction {
#tx;
constructor(tx) {
this.#tx = tx;
const onAbort = () => {
cleanup();
};
const onComplete = () => {
cleanup();
};
const cleanup = () => {
this.#tx = null;
tx.removeEventListener('abort', onAbort);
tx.removeEventListener('complete', onComplete);
};
tx.addEventListener('abort', onAbort);
tx.addEventListener('complete', onComplete);
}
get tx() {
if (!this.#tx)
throw new Error('Transaction already ended');
return this.#tx;
}
async abort() {
const { tx } = this;
this.#tx = null;
tx.abort();
}
async commit() {
const { tx } = this;
this.#tx = null;
tx.commit?.();
}
objectStore(name) {
const store = this.tx.objectStore(name);
return new DBObjectStore(store);
}
[Symbol.dispose]() {
if (this.#tx)
this.commit();
}
}
//# sourceMappingURL=db-transaction.js.map