From 1a6688e85ee624d89c7aee4c6c9b60cb4693aa96 Mon Sep 17 00:00:00 2001 From: Guy Ben-Aharon Date: Thu, 11 Sep 2025 12:32:58 +0300 Subject: [PATCH] alignment (#912) --- src/lib/domain/diff/diff.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/lib/domain/diff/diff.ts b/src/lib/domain/diff/diff.ts index a93b6d47..6129f523 100644 --- a/src/lib/domain/diff/diff.ts +++ b/src/lib/domain/diff/diff.ts @@ -57,3 +57,40 @@ export type DiffObject< | FieldDiff['object'] | IndexDiff['object'] | RelationshipDiff['object']; + +type ExtractDiffKind = T extends { object: infer O; type: infer Type } + ? T extends { attribute: infer A } + ? { object: O; type: Type; attribute: A } + : { object: O; type: Type } + : never; + +export type DiffKind< + TTable = DBTable, + TField = DBField, + TIndex = DBIndex, + TRelationship = DBRelationship, +> = ExtractDiffKind>; + +export const isDiffOfKind = < + TTable = DBTable, + TField = DBField, + TIndex = DBIndex, + TRelationship = DBRelationship, +>( + diff: ChartDBDiff, + kind: DiffKind +): boolean => { + if ('attribute' in kind) { + return ( + diff.object === kind.object && + diff.type === kind.type && + diff.attribute === kind.attribute + ); + } + + if ('attribute' in diff) { + return false; + } + + return diff.object === kind.object && diff.type === kind.type; +};