Skip to content

Database diagrams editor that allows you to visualize and design your DB with a single query.

alignment (#912)

Guy Ben-Aharon1a6688e85ee6
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<TField>['object']
| IndexDiff<TIndex>['object']
| RelationshipDiff<TRelationship>['object'];
+
+type ExtractDiffKind<T> = 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<ChartDBDiff<TTable, TField, TIndex, TRelationship>>;
+
+export const isDiffOfKind = <
+ TTable = DBTable,
+ TField = DBField,
+ TIndex = DBIndex,
+ TRelationship = DBRelationship,
+>(
+ diff: ChartDBDiff<TTable, TField, TIndex, TRelationship>,
+ kind: DiffKind<TTable, TField, TIndex, TRelationship>
+): 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;
+};