const RETENTION_POLICY_MIN_AGE_SECONDS = 60 ; const TIME_UNITS = [ 'nanos' , 'micros' , 'ms' , 's' , 'm' , 'h' , 'd' ] ; param value export function continuousModeDelayValidator ( value ) { return value . match ( /^(0|\d*(nanos|micros|ms|s|m|h|d))$/ ) !== null ; } param value export interface ParsedDuration { number : number ; timeUnit : string ; } export function parseDuration ( value ) { if ( typeof value !== 'string' || value === null ) { return ; } const regexStr = value . match ( /[a-z]+|[^a-z]+/gi ) ; if ( regexStr === null || ( Array . isArray ( regexStr ) && regexStr . length !== 2 ) ) { return ; } const number = + regexStr [ 0 ] ; const timeUnit = regexStr [ 1 ] ; if ( isNaN ( number ) || ! Number . isInteger ( number ) ) { return ; } if ( ! TIME_UNITS . includes ( timeUnit ) ) { return ; } return { number , timeUnit } ; } export function isValidRetentionPolicyMaxAge ( { number , timeUnit } ) { return ( ( timeUnit === 'nanos' && number >= RETENTION_POLICY_MIN_AGE_SECONDS * 1000000000 ) || ( timeUnit === 'micros' && number >= RETENTION_POLICY_MIN_AGE_SECONDS * 1000000 ) || ( timeUnit === 'ms' && number >= RETENTION_POLICY_MIN_AGE_SECONDS * 1000 ) || ( timeUnit === 's' && number >= RETENTION_POLICY_MIN_AGE_SECONDS ) || ( ( timeUnit === 'm' || timeUnit === 'h' || timeUnit === 'd' ) && number >= 1 ) ) ; } param value export function retentionPolicyMaxAgeValidator ( value ) { const parsedValue = parseDuration ( value ) ; if ( parsedValue === undefined ) { return false ; } return isValidRetentionPolicyMaxAge ( parsedValue ) ; } export function isValidFrequency ( { number , timeUnit } ) { return ( ( timeUnit === 's' && number <= 3600 ) || ( timeUnit === 'm' && number <= 60 ) || ( timeUnit === 'h' && number === 1 ) ) ; } param value export const transformFrequencyValidator = ( value ) : boolean => { if ( typeof value !== 'string' || value === null ) { return false ; } const regexStr = value . match ( /[a-z]+|[^a-z]+/gi ) ; if ( regexStr === null || ( Array . isArray ( regexStr ) && regexStr . length !== 2 ) ) { return false ; } const number = + regexStr [ 0 ] ; const timeUnit = regexStr [ 1 ] ; if ( isNaN ( number ) || ! Number . isInteger ( number ) || number === 0 ) { return false ; } return isValidFrequency ( { number , timeUnit } ) ; } ; param value export function transformSettingsMaxPageSearchSizeValidator ( value ) { return value >= 10 && value <= 10000 ; }