@@ -115,6 +115,32 @@ function dedupeTuples<T extends [object | undefined, object | undefined]>(
115115 return result
116116}
117117
118+ function removeRedundantPartialPairs < T extends [ object | undefined , object | undefined ] > (
119+ tuples : T [ ] ,
120+ ) : T [ ] {
121+ const completeAtPosition = [ new Set < object > ( ) , new Set < object > ( ) ] as const
122+
123+ // First pass: identify all values that appear in complete pairs by position
124+ for ( const [ a , b ] of tuples ) {
125+ if ( a !== undefined && b !== undefined ) {
126+ completeAtPosition [ 0 ] . add ( a )
127+ completeAtPosition [ 1 ] . add ( b )
128+ }
129+ }
130+
131+ // Second pass: filter out partial pairs that are consumed by a complete pair
132+ return tuples . filter ( ( [ a , b ] ) => {
133+ const isPartial = a === undefined || b === undefined
134+ if ( ! isPartial ) return true // Keep all complete pairs
135+
136+ // For partial pairs, only keep if there's no corresponding complete pair
137+ // with the defined value at corresponding position
138+ return a === undefined
139+ ? ! completeAtPosition [ 1 ] . has ( b ! )
140+ : ! completeAtPosition [ 0 ] . has ( a )
141+ } )
142+ }
143+
118144export function normalizeOperationIds ( operations : ResolvedOperation [ ] , apiBuilder : ApiBuilder , groupSlug : string ) : [ ( NormalizedOperationId | OperationId ) [ ] , Record < NormalizedOperationId | OperationId , ResolvedOperation > ] {
119145 const normalizedOperationIdToOperation : Record < NormalizedOperationId | OperationId , ResolvedOperation > = { }
120146 operations . forEach ( operation => {
@@ -200,7 +226,7 @@ export const calculatePairedDocs = async (
200226 const currDoc = current && currDocuments . find ( document => document . slug === current . documentId )
201227 pairedDocs . push ( [ prevDoc , currDoc ] )
202228 }
203- return dedupeTuples ( pairedDocs )
229+ return removeRedundantPartialPairs ( dedupeTuples ( pairedDocs ) )
204230}
205231
206232export const comparePairedDocs = async (
0 commit comments