import { pipe } from 'fp-ts/lib/pipeable' ; import { tryCatch , fold } from 'fp-ts/lib/Either' ; import { DEPRECATION_WARNING_UPPER_LIMIT } from '../../../common/constants' ; import { ReindexStep } from '../../../common/types' ; export const validateRegExpString = ( s ) => pipe ( tryCatch ( ( ) => new RegExp ( s ) , ( e ) => ( e as Error ) . message ) , fold ( ( errorMessage ) => errorMessage , ( ) => '' ) ) ; export const getDeprecationsUpperLimit = ( count ) => { if ( count > DEPRECATION_WARNING_UPPER_LIMIT ) { return `${ DEPRECATION_WARNING_UPPER_LIMIT }+` ; } return count . toString ( ) ; } ; export const getReindexProgressLabel = ( reindexTaskPercComplete , lastCompletedStep , hasExistingAliases = false ) : string => { let percentsComplete = 0 ; switch ( lastCompletedStep ) { case ReindexStep . created : percentsComplete = 0 ; break ; case ReindexStep . readonly : { percentsComplete = 5 ; break ; } case ReindexStep . newIndexCreated : { percentsComplete = 10 ; break ; } case ReindexStep . reindexStarted : { percentsComplete = reindexTaskPercComplete !== null ? 10 + Math . round ( reindexTaskPercComplete * ( hasExistingAliases ? 75 : 80 ) ) : 10 ; break ; } case ReindexStep . reindexCompleted : { percentsComplete = hasExistingAliases ? 85 : 90 ; break ; } case ReindexStep . aliasCreated : { percentsComplete = hasExistingAliases ? 90 : 95 ; break ; } case ReindexStep . originalIndexDeleted : { percentsComplete = hasExistingAliases ? 95 : 100 ; break ; } case ReindexStep . existingAliasesUpdated : { percentsComplete = 100 ; break ; } } return `${ percentsComplete }%` ; } ;