opral / lix-sdk

1 stars 0 forks source link

add `lix.resolveConflict()` #49

Closed samuelstroschein closed 2 months ago

samuelstroschein commented 2 months ago

Context

Apps (users) need a way to resolve conflicts by expressing a "take this change and not this one".

https://github.com/opral/monorepo/pull/3067 did introduce the possibility of merging and the concept of conflicts but no way to resolve conflicts.

Proposal

Implement a lix.resolveConflict({ conflict, pick: ""}) API.

Potential logic

  1. A user expresses that `` is the chosen winner of a conflict.
  2. The lix app calls lix.resolveConflict
  3. If the picked change is not in the sequence but the loser is, swap both changes (put the picked change in the sequence, the loser out of the sequence).
  4. Mark the conflict as resolved by setting conflict.picked_change_id

Workaround for Fink2 that avoids MESDK-175

Below is pseudocode that should work to simulate a sequence of

await lix.db.selectFrom("change")
   .selectAll()
   .where((eb) =>
   eb.or([
     // don't show conflicting changes except if they are the picked change
     eb(
     "change.id",
     "=",
     project.lix.db.selectFrom("conflict").select("conflict.picked_change")
    ),
    // don't show onf
    eb(
     "change.id",
     "not in",
       eb(project.lix.db
        .selectFrom("conflict")
        .select("conflict.conflicting_change_id")),
       ])
    ),
   ])
  )