import { computeSimilarity } from "./similarity" ; import { Headers , TapeRecord } from "./tape" ; param records param tapeReplayCount export function findNextRecordToReplay ( records , replayedTapes ) { for ( const record of records ) { if ( ! replayedTapes . has ( record ) ) { return record ; } } if ( records . length === 0 ) { return null ; } else { return records [ records . length - 1 ] ; } } /**
 * Finds a list of "best matching records" for a particular request, in order
 * of execution.
 *
 * For example if three requests had been recorded to /pets, there will be three
 * records returned when a request for /pets is matched (but no other records
 * against different paths).
 */ export function findRecordMatches ( tapeRecords , requestMethod , requestPath , requestHeaders , requestBody ) { let bestSimilarityScore = + Infinity ; let bestMatches = [ ] ; for ( const potentialMatch of tapeRecords ) { const similarityScore = computeSimilarity ( requestMethod , requestPath , requestHeaders , requestBody , potentialMatch ) ; if ( similarityScore < bestSimilarityScore ) { bestSimilarityScore = similarityScore ; bestMatches = [ potentialMatch ] ; } else if ( similarityScore === bestSimilarityScore ) { bestMatches . push ( potentialMatch ) ; } } if ( isFinite ( bestSimilarityScore ) ) { return bestMatches ; } else { return [ ] ; } }