import { SavedObject , SavedObjectsImportRetry } from '../../types' ; import type { ImportStateMap } from './types' ; interface GetImportStateMapForRetriesParams { objects : SavedObject [ ] ; retries : SavedObjectsImportRetry [ ] ; createNewCopies : boolean ; } /**
 * Assume that all objects exist in the `retries` map (due to filtering at the beginning of `resolveSavedObjectsImportErrors`).
 */ export function getImportStateMapForRetries ( params ) { const { objects , retries , createNewCopies } = params ; const retryMap = retries . reduce ( ( acc , cur ) => acc . set ( `${ cur . type }:${ cur . id }` , cur ) , new Map < string , SavedObjectsImportRetry > ( ) ) ; const importStateMap = new Map ( ) ; objects . forEach ( ( { type , id } ) => { const retry = retryMap . get ( `${ type }:${ id }` ) ; if ( ! retry ) { throw new Error ( `Retry was expected for "${ type }:${ id }" but not found` ) ; } const { destinationId } = retry ; const omitOriginId = createNewCopies || Boolean ( retry . createNewCopy ) ; if ( destinationId && destinationId !== id ) { importStateMap . set ( `${ type }:${ id }` , { destinationId , omitOriginId } ) ; } } ) ; return importStateMap ; }