Skip to content

Commit

Permalink
chore: remove args from storage engine startTransaction def
Browse files Browse the repository at this point in the history
  • Loading branch information
litcodeur committed Feb 21, 2024
1 parent cb7b283 commit db951ee
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 24 deletions.
7 changes: 2 additions & 5 deletions src/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ export class Database<
localMutators[typedKey] = async (args: any) => {
await this.initialize();

const storageEngineTransaction = this.#storageEngine.startTransaction(
"ALL",
"readwrite"
);
const storageEngineTransaction = this.#storageEngine.startTransaction();

const internalWriteTransaction = new InternalWriteTransaction(
this.#schema,
Expand Down Expand Up @@ -180,7 +177,7 @@ export class Database<

async #processBatchReadQueue() {
const tx = new ReadTransaction(
this.#storageEngine.startTransaction("ALL", "readonly"),
this.#storageEngine.startTransaction(),
this.#schema
);

Expand Down
9 changes: 6 additions & 3 deletions src/LockController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ export function createIDBStorageEnginePersistentStorage(
): PersistentStorage {
return {
async getItem<T>(key: string) {
const documentResult = await engine.queryByKey(
const tx = engine.startTransaction();
const documentResult = await tx.queryByKey(
INTERNAL_SCHEMA[META].name,
key
);
return documentResult.get(key) as T | undefined;
},
async setItem<T>(key: string, value: T) {
const result = await engine.update({
const tx = engine.startTransaction();
const result = await tx.update({
collectionName: INTERNAL_SCHEMA[META].name,
key,
value: value as any,
Expand All @@ -30,7 +32,8 @@ export function createIDBStorageEnginePersistentStorage(
return result?.value as T;
},
async removeItem<T>(key: string) {
const result = await engine.delete({
const tx = engine.startTransaction();
const result = await tx.delete({
collectionName: INTERNAL_SCHEMA[META].name,
key,
});
Expand Down
2 changes: 1 addition & 1 deletion src/QueryEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class QueryEngine {

async #processQueue() {
try {
const tx = this.#storageEngine.startTransaction("ALL", "readonly");
const tx = this.#storageEngine.startTransaction();

for (let [_, { option, resolve }] of this.#queue) {
if (isQueryOptionDocumentQueryOption(option)) {
Expand Down
22 changes: 11 additions & 11 deletions src/SyncManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class SyncManager<
}

async #getHasUnProcessedMutation() {
const tx = this.#storageEngine.startTransaction("ALL", "readonly");
const tx = this.#storageEngine.startTransaction();

const allMutationsMap = await tx.queryAll<DatabaseMutation>(
INTERNAL_SCHEMA[MUTATION].name
Expand All @@ -117,7 +117,7 @@ export class SyncManager<
}

async #getNextUnPushedMutation() {
const tx = this.#storageEngine.startTransaction("ALL", "readonly");
const tx = this.#storageEngine.startTransaction();

const allMutationsMap = await tx.queryAll<DatabaseMutation>(
INTERNAL_SCHEMA[MUTATION].name
Expand Down Expand Up @@ -155,8 +155,7 @@ export class SyncManager<
storageEngineTransaction?: EnhancedStorageEngineTransaction
) {
const tx =
storageEngineTransaction ??
this.#storageEngine.startTransaction("ALL", "readwrite");
storageEngineTransaction ?? this.#storageEngine.startTransaction();
try {
await tx.delete<DatabaseMutation>({
collectionName: INTERNAL_SCHEMA[MUTATION].name,
Expand Down Expand Up @@ -199,7 +198,7 @@ export class SyncManager<
tx?: EnhancedStorageEngineTransaction
) {
const storageEngineTransaction =
tx ?? this.#storageEngine.startTransaction("ALL", "readwrite");
tx ?? this.#storageEngine.startTransaction();

for (let collectionIdentifier in change) {
const collection = this.#schema[collectionIdentifier as any];
Expand Down Expand Up @@ -260,7 +259,7 @@ export class SyncManager<
remoteResolver.shouldRetry ?? true,
{
onRetry: async (retryCount) => {
const tx = this.#storageEngine.startTransaction("ALL", "readwrite");
const tx = this.#storageEngine.startTransaction();
await tx.update<DatabaseMutation>({
collectionName: INTERNAL_SCHEMA[MUTATION].name,
key: mutation.id,
Expand All @@ -273,7 +272,7 @@ export class SyncManager<
}
);

const tx = this.#storageEngine.startTransaction("ALL", "readwrite");
const tx = this.#storageEngine.startTransaction();

try {
await tx.update<DatabaseMutation>({
Expand All @@ -294,7 +293,7 @@ export class SyncManager<
tx.rollback();
}
} catch (error) {
const tx = this.#storageEngine.startTransaction("ALL", "readwrite");
const tx = this.#storageEngine.startTransaction();
await tx.delete<DatabaseMutation>({
collectionName: INTERNAL_SCHEMA[MUTATION].name,
key: mutation.id,
Expand Down Expand Up @@ -389,7 +388,8 @@ export class SyncManager<
let result: PullResponse<TDatabaseSchema> | undefined = undefined;

try {
const cursor = await this.#storageEngine.queryByKey<CursroMeta>(
const tx = this.#storageEngine.startTransaction();
const cursor = await tx.queryByKey<CursroMeta>(
INTERNAL_SCHEMA[META].name,
"cursor"
);
Expand All @@ -401,7 +401,7 @@ export class SyncManager<
await this.#lockController.request(
`pull:${this.#storageEngine.name}`,
async () => {
const tx = this.#storageEngine.startTransaction("ALL", "readwrite");
const tx = this.#storageEngine.startTransaction();
try {
const allMutationsMap = await tx.queryAll<DatabaseMutation>(
INTERNAL_SCHEMA[MUTATION].name
Expand Down Expand Up @@ -453,7 +453,7 @@ export class SyncManager<
}

async getPendingMutationsCount() {
const tx = this.#storageEngine.startTransaction("ALL", "readonly");
const tx = this.#storageEngine.startTransaction();

const allMutationsMap = await tx.queryAll<DatabaseMutation>(
INTERNAL_SCHEMA[MUTATION].name
Expand Down
5 changes: 1 addition & 4 deletions src/types/StorageEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ export interface StorageEngine<

subscribeToCDC(subscriber: StorageEngineCDCEventSubscriber): () => void;

startTransaction(
collectionNames: Array<string> | "ALL",
mode: StorageEngineTransactionMode
): EnhancedStorageEngineTransaction;
startTransaction(): EnhancedStorageEngineTransaction;

get name(): string;
}

0 comments on commit db951ee

Please sign in to comment.