import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey' ; import type { EsIndex } from '../types/es_index' ; import { isPopulatedObject } from '../shared_imports' ; import type { FieldHistogramsResponseSchema } from './field_histograms' ; import type { GetTransformsAuditMessagesResponseSchema } from './audit_messages' ; import type { DeleteTransformsResponseSchema } from './delete_transforms' ; import type { StartTransformsResponseSchema } from './start_transforms' ; import type { StopTransformsResponseSchema } from './stop_transforms' ; import type { GetTransformNodesResponseSchema , GetTransformsResponseSchema , PostTransformsPreviewResponseSchema , PutTransformsResponseSchema , } from './transforms' ; import type { GetTransformsStatsResponseSchema } from './transforms_stats' ; import type { PostTransformsUpdateResponseSchema } from './update_transforms' ; const isGenericResponseSchema = < T > ( arg ) : arg is T => { return isPopulatedObject ( arg , [ 'count' , 'transforms' ] ) && Array . isArray ( arg . transforms ) ; } ; export const isGetTransformNodesResponseSchema = ( arg ) : arg is GetTransformNodesResponseSchema => { return isPopulatedObject ( arg , [ 'count' ] ) && typeof arg . count === 'number' ; } ; export const isGetTransformsResponseSchema = ( arg ) : arg is GetTransformsResponseSchema => { return isGenericResponseSchema < GetTransformsResponseSchema > ( arg ) ; } ; export const isGetTransformsStatsResponseSchema = ( arg ) : arg is GetTransformsStatsResponseSchema => { return isGenericResponseSchema < GetTransformsStatsResponseSchema > ( arg ) ; } ; export const isDeleteTransformsResponseSchema = ( arg ) : arg is DeleteTransformsResponseSchema => { return ( isPopulatedObject ( arg ) && Object . values ( arg ) . every ( ( d ) => isPopulatedObject ( d , [ 'transformDeleted' ] ) ) ) ; } ; export const isEsIndices = ( arg ) : arg is EsIndex [ ] => { return Array . isArray ( arg ) ; } ; export const isEsSearchResponse = ( arg ) : arg is estypes . SearchResponse => { return isPopulatedObject ( arg , [ 'hits' ] ) ; } ; type SearchResponseWithAggregations = Required < Pick < estypes . SearchResponse , 'aggregations' > > & estypes . SearchResponse ; export const isEsSearchResponseWithAggregations = ( arg ) : arg is SearchResponseWithAggregations => { return isEsSearchResponse ( arg ) && { } . hasOwnProperty . call ( arg , 'aggregations' ) ; } ; export const isMultiBucketAggregate = < TBucket = unknown > ( arg ) : arg is estypes . AggregationsMultiBucketAggregateBase < TBucket > => { return isPopulatedObject ( arg , [ 'buckets' ] ) ; } ; export const isFieldHistogramsResponseSchema = ( arg ) : arg is FieldHistogramsResponseSchema => { return Array . isArray ( arg ) ; } ; export const isGetTransformsAuditMessagesResponseSchema = ( arg ) : arg is GetTransformsAuditMessagesResponseSchema => { return Array . isArray ( arg ) ; } ; export const isPostTransformsPreviewResponseSchema = ( arg ) : arg is PostTransformsPreviewResponseSchema => { return ( isPopulatedObject ( arg , [ 'generated_dest_index' , 'preview' ] ) && typeof arg . generated_dest_index !== undefined && Array . isArray ( arg . preview ) ) ; } ; export const isPostTransformsUpdateResponseSchema = ( arg ) : arg is PostTransformsUpdateResponseSchema => { return isPopulatedObject ( arg , [ 'id' ] ) && typeof arg . id === 'string' ; } ; export const isPutTransformsResponseSchema = ( arg ) : arg is PutTransformsResponseSchema => { return ( isPopulatedObject ( arg , [ 'transformsCreated' , 'errors' ] ) && Array . isArray ( arg . transformsCreated ) && Array . isArray ( arg . errors ) ) ; } ; const isGenericSuccessResponseSchema = ( arg ) => isPopulatedObject ( arg ) && Object . values ( arg ) . every ( ( d ) => isPopulatedObject ( d , [ 'success' ] ) ) ; export const isStartTransformsResponseSchema = ( arg ) : arg is StartTransformsResponseSchema => { return isGenericSuccessResponseSchema ( arg ) ; } ; export const isStopTransformsResponseSchema = ( arg ) : arg is StopTransformsResponseSchema => { return isGenericSuccessResponseSchema ( arg ) ; } ;