import * as t from 'io-ts' ; import { Dataset } from '../../../rule_registry/server' ; import { createObservabilityServerRoute } from './create_observability_server_route' ; import { createObservabilityServerRouteRepository } from './create_observability_server_route_repository' ; const alertsDynamicIndexPatternRoute = createObservabilityServerRoute ( { endpoint : 'GET /api/observability/rules/alerts/dynamic_index_pattern' , options : { tags : [ ] , } , params : t . type ( { query : t . type ( { registrationContexts : t . array ( t . string ) , namespace : t . string , } ) , } ) , handler : async ( { ruleDataService , params } ) => { const { namespace , registrationContexts } = params . query ; const indexNames = registrationContexts . flatMap ( ( registrationContext ) => { const indexName = ruleDataService . findIndexByName ( registrationContext , Dataset . alerts ) ?. getPrimaryAlias ( namespace ) ; if ( indexName != null ) { return [ indexName ] ; } else { return [ ] ; } } ) ; return indexNames ; } , } ) ; export const rulesRouteRepository = createObservabilityServerRouteRepository ( ) . add ( alertsDynamicIndexPatternRoute ) ;