From 2c299e314e9c3f69c6e07639df7400740f2e432e Mon Sep 17 00:00:00 2001 From: Vitor Gomes Date: Thu, 3 Oct 2024 10:11:46 -0300 Subject: [PATCH 1/2] Add resolveAll to the ConflictResolver --- CHANGELOG.md | 3 +++ src/utils/MineWinsConflictsResolver.ts | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0567aefb..2be7ce20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Added +- resolveAll to `MineWinsConflictsResolver` to handle an array of conflicts. + ## [6.47.0] - 2024-06-11 ### Added - Add option to save asynchronous cache diff --git a/src/utils/MineWinsConflictsResolver.ts b/src/utils/MineWinsConflictsResolver.ts index 3f994d40..d2e08a81 100644 --- a/src/utils/MineWinsConflictsResolver.ts +++ b/src/utils/MineWinsConflictsResolver.ts @@ -48,6 +48,21 @@ export class MineWinsConflictsResolver implements ConflictsResolver { }) } + public async resolveAll() { + return await this.client.getConflicts>(this.bucket).then((data) => { + const { data: conflicts }: { data: VBaseConflictData[] } = data + + const resolved = conflicts.map((conflict) => { + conflict.base.parsedContent = this.parseConflict(conflict.base) + conflict.master.parsedContent = this.parseConflict(conflict.master) + conflict.mine.parsedContent = this.parseConflict(conflict.mine) + return this.resolveConflictMineWins(conflict) + }) + + return resolved as any + }) + } + protected mergeMineWins(base: Configuration, master: Configuration, mine: Configuration) { if (isArray(master)) { return this.mergeMineWinsArray((base || []) as ConfigurationData[], master, (mine || []) as ConfigurationData[]) From 1c052c4f4c55283fce4aeb32a3880a6badce2f6d Mon Sep 17 00:00:00 2001 From: Vitor Gomes Date: Thu, 10 Oct 2024 10:42:33 -0300 Subject: [PATCH 2/2] Avoid using async/await with then callbacks --- src/utils/MineWinsConflictsResolver.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/utils/MineWinsConflictsResolver.ts b/src/utils/MineWinsConflictsResolver.ts index d2e08a81..882caec6 100644 --- a/src/utils/MineWinsConflictsResolver.ts +++ b/src/utils/MineWinsConflictsResolver.ts @@ -49,18 +49,17 @@ export class MineWinsConflictsResolver implements ConflictsResolver { } public async resolveAll() { - return await this.client.getConflicts>(this.bucket).then((data) => { - const { data: conflicts }: { data: VBaseConflictData[] } = data - - const resolved = conflicts.map((conflict) => { - conflict.base.parsedContent = this.parseConflict(conflict.base) - conflict.master.parsedContent = this.parseConflict(conflict.master) - conflict.mine.parsedContent = this.parseConflict(conflict.mine) - return this.resolveConflictMineWins(conflict) - }) - - return resolved as any + const conflictsResponse = await this.client.getConflicts>(this.bucket) + const { data: conflicts }: { data: VBaseConflictData[] } = conflictsResponse + + const resolvedConflicts = conflicts.map((conflict) => { + conflict.base.parsedContent = this.parseConflict(conflict.base) + conflict.master.parsedContent = this.parseConflict(conflict.master) + conflict.mine.parsedContent = this.parseConflict(conflict.mine) + return this.resolveConflictMineWins(conflict) }) + + return resolvedConflicts } protected mergeMineWins(base: Configuration, master: Configuration, mine: Configuration) {