1 import type { ItemContent, ItemExtraField, ItemRevision, ItemType, Metadata } from '@proton/pass/types';
2 import isDeepEqual from '@proton/shared/lib/helpers/isDeepEqual';
4 type Diff<T extends object> = Partial<Record<keyof T, boolean>>;
6 export type ItemDiff<T extends ItemType> = {
7 content: Diff<ItemContent<T>>;
8 metadata: Diff<Metadata>;
9 extraFields: Diff<ItemExtraField[]>;
12 const diffedKeys = <T extends object>(a: T, b: T): Diff<T> =>
13 (Object.keys(a) as (keyof T)[]).reduce<Diff<T>>((diff, key) => {
14 if (!isDeepEqual(a[key], b[key])) diff[key] = true;
18 export const itemDiff = <T extends ItemType>(
19 { data: a }: ItemRevision<T>,
20 { data: b }: ItemRevision<T>
22 content: diffedKeys(a.content, b.content),
23 metadata: diffedKeys(a.metadata, b.metadata),
24 extraFields: diffedKeys(a.extraFields, b.extraFields),