import { TileMetaFeature } from '../../../common/descriptor_types' ; import { FIELD_ORIGIN } from '../../../common/constants' ; import { IVectorSource } from '../sources/vector_source' ; import { ITooltipProperty , TooltipProperty } from '../tooltips/tooltip_property' ; export interface IField { getName ( ) : string ; getMbFieldName ( ) : string ; getRootName ( ) : string ; canValueBeFormatted ( ) : boolean ; getLabel ( ) : Promise < string > ; getDataType ( ) : Promise < string > ; createTooltipProperty ( value ) : Promise < ITooltipProperty > ; getSource ( ) : IVectorSource ; getOrigin ( ) : FIELD_ORIGIN ; isValid ( ) : boolean ; getExtendedStatsFieldMetaRequest ( ) : Promise < unknown | null > ; getPercentilesFieldMetaRequest ( percentiles ) : Promise < unknown | null > ; getCategoricalFieldMetaRequest ( size ) : Promise < unknown | null > ; supportsFieldMetaFromLocalData ( ) : boolean ; supportsFieldMetaFromEs ( ) : boolean ; isEqual ( field ) : boolean ; pluckRangeFromTileMetaFeature ( metaFeature ) : { min : number ; max : number ; } | null ; isCount ( ) : boolean ; } export class AbstractField implements IField { private readonly _fieldName : string ; private readonly _origin : FIELD_ORIGIN ; constructor ( { fieldName , origin } ) { this . _fieldName = fieldName ; this . _origin = origin || FIELD_ORIGIN . SOURCE ; } supportsFieldMetaFromEs ( ) { throw new Error ( 'must implement AbstractField#supportsFieldMetaFromEs' ) ; } supportsFieldMetaFromLocalData ( ) { throw new Error ( 'must implement AbstractField#supportsFieldMetaFromLocalData' ) ; } getName ( ) { return this . _fieldName ; } getMbFieldName ( ) { return this . getName ( ) ; } getRootName ( ) { return this . getName ( ) ; } canValueBeFormatted ( ) { return false ; } getSource ( ) { throw new Error ( 'must implement AbstractField#getSource' ) ; } isValid ( ) { return ! ! this . _fieldName ; } async getDataType ( ) { return 'string' ; } async getLabel ( ) { return this . _fieldName ; } async createTooltipProperty ( value ) { const label = await this . getLabel ( ) ; return new TooltipProperty ( this . getName ( ) , label , value ) ; } getOrigin ( ) { return this . _origin ; } async getExtendedStatsFieldMetaRequest ( ) { return null ; } async getPercentilesFieldMetaRequest ( percentiles ) { return null ; } async getCategoricalFieldMetaRequest ( size ) { return null ; } isEqual ( field ) { return this . _origin === field . getOrigin ( ) && this . _fieldName === field . getName ( ) ; } pluckRangeFromTileMetaFeature ( metaFeature ) { return null ; } isCount ( ) { return false ; } }