import { xLuceneFieldType , ESFieldType , xLuceneTypeConfig , DateFormat } from '@terascope/types' ; import { withoutNil } from '@terascope/utils' ; import BaseType from '../base-type' ; import { GraphQLType , TypeESMapping } from '../../interfaces' ; export default class DateType extends BaseType { toESMapping ( _version ? ) { let format ; if ( this . config . format && ( ! ( this . config . format in DateFormat ) || this . config . format === DateFormat . epoch || this . config . format === DateFormat . seconds || this . config . format === DateFormat . epoch_millis || this . config . format === DateFormat . milliseconds ) ) { format = this . config . format as string ; } if ( format === DateFormat . milliseconds ) { format = DateFormat . epoch_millis ; } if ( format === DateFormat . seconds ) { format = DateFormat . epoch ; } return { mapping : { [ this . field ] : withoutNil ( { type : 'date' as ESFieldType , format , index : this . config . indexed === false ? false : undefined } ) } } ; } toGraphQL ( ) { return this . _formatGql ( 'String' ) ; } toXlucene ( ) { return { [ this . field ] : xLuceneFieldType . Date } ; } }