import { schema } from '@kbn/config-schema' ; import moment from 'moment-timezone' ; import { assertNever } from '@kbn/std' ; import { TriggeringPolicy } from './policy' ; import { RollingFileContext } from '../rolling_file_context' ; import { sizeLimitTriggeringPolicyConfigSchema , SizeLimitTriggeringPolicyConfig , SizeLimitTriggeringPolicy , } from './size_limit' ; import { TimeIntervalTriggeringPolicyConfig , TimeIntervalTriggeringPolicy , timeIntervalTriggeringPolicyConfigSchema , } from './time_interval' ; export type { TriggeringPolicy } from './policy' ; /**
 * Any of the existing policy's configuration
 *
 * See  SizeLimitTriggeringPolicyConfig and  TimeIntervalTriggeringPolicyConfig export type TriggeringPolicyConfig = SizeLimitTriggeringPolicyConfig | TimeIntervalTriggeringPolicyConfig ; const defaultPolicy = { type : 'time-interval' , interval : moment . duration ( 24 , 'hour' ) , modulate : true , } ; export const triggeringPolicyConfigSchema = schema . oneOf ( [ sizeLimitTriggeringPolicyConfigSchema , timeIntervalTriggeringPolicyConfigSchema ] , { defaultValue : defaultPolicy } ) ; export const createTriggeringPolicy = ( config , context ) : TriggeringPolicy => { switch ( config . type ) { case 'size-limit' : return new SizeLimitTriggeringPolicy ( config , context ) ; case 'time-interval' : return new TimeIntervalTriggeringPolicy ( config , context ) ; default : return assertNever ( config ) ; } } ;