import * as TaskEither from 'fp-ts/lib/TaskEither' ; import * as Option from 'fp-ts/lib/Option' ; import { flow } from 'fp-ts/lib/function' ; import { waitForTask , WaitForTaskCompletionTimeout } from './wait_for_task' ; import { RetryableEsClientError } from './catch_retryable_es_client_errors' ; export const waitForPickupUpdatedMappingsTask = flow ( waitForTask , TaskEither . chain ( ( res ) : TaskEither . TaskEither < RetryableEsClientError | WaitForTaskCompletionTimeout , 'pickup_updated_mappings_succeeded' > => { if ( Option . isSome ( res . failures ) ) { throw new Error ( 'pickupUpdatedMappings task failed with the following failures:\n' + JSON . stringify ( res . failures . value ) ) ; } else if ( Option . isSome ( res . error ) ) { throw new Error ( 'pickupUpdatedMappings task failed with the following error:\n' + JSON . stringify ( res . error . value ) ) ; } else { return TaskEither . right ( 'pickup_updated_mappings_succeeded' as const ) ; } } ) ) ;