-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathConflict.ts
More file actions
30 lines (28 loc) · 1.03 KB
/
Conflict.ts
File metadata and controls
30 lines (28 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { array, nonEmptyArray, option, pipe } from '@code-expert/prelude';
import { eqFsNode } from '@/lib/tauri/fs';
import { LocalNodeChange, RemoteNodeChange, remoteChangeType } from './Change';
export interface Conflict {
path: string;
changeRemote: RemoteNodeChange['change'];
changeLocal: LocalNodeChange['change'];
}
export const getConflicts = (
local: NonEmptyArray<LocalNodeChange>,
remote: NonEmptyArray<RemoteNodeChange>,
): option.Option<NonEmptyArray<Conflict>> =>
pipe(
local,
array.intersection<LocalNodeChange>(eqFsNode)(remote),
array.map((changeLocal) => ({
path: changeLocal.path,
changeLocal: changeLocal.change,
changeRemote: pipe(
remote,
array.findFirst((changeRemote) => eqFsNode.equals(changeLocal, changeRemote)),
option.map(({ change }) => change),
// fixme: don't do this: instead, replace array.intersection with a groupBy(getPath)
option.getOrElseW(() => remoteChangeType.noChange()),
),
})),
nonEmptyArray.fromArray,
);