import { FluxTableColumn , ColumnType } from './FluxTableColumn' ; import { IllegalArgumentError } from '../errors' ; const identity = ( x ) : any => x ; /**
 * A dictionary of serializers of particular types returned by a flux query.
 * See  https export const typeSerializers = { boolean : ( x ) : any => x === 'true' , unsignedLong : ( x ) : any => ( x === '' ? null : + x ) , long : ( x ) : any => ( x === '' ? null : + x ) , double ( x ) { switch ( x ) { case '' : return null ; case '+Inf' : return Number . POSITIVE_INFINITY ; case '-Inf' : return Number . NEGATIVE_INFINITY ; default : return + x ; } } , string : identity , base64Binary : identity , duration : ( x ) : any => ( x === '' ? null : x ) , 'dateTime:RFC3339' : ( x ) : any => ( x === '' ? null : x ) , } ; remarks export function serializeDateTimeAsDate ( ) { typeSerializers [ 'dateTime:RFC3339' ] = ( x ) : any => x === '' ? null : new Date ( Date . parse ( x ) ) ; } remarks export function serializeDateTimeAsNumber ( ) { typeSerializers [ 'dateTime:RFC3339' ] = ( x ) : any => x === '' ? null : Date . parse ( x ) ; } /**
 * serializeDateTimeAsString changes type serializers to return string values
 * for `dateTime:RFC3339` query result data type.  Empty value is converted to null.
 */ export function serializeDateTimeAsString ( ) { typeSerializers [ 'dateTime:RFC3339' ] = ( x ) : any => x === '' ? null : x ; } /**
 * Represents metadata of a  http .
  export interface FluxTableMetaData { /**
     * Table columns.
     */ columns : Array < FluxTableColumn > ; param label returns throws column ( label ) : FluxTableColumn ; param values toObject ( values ) : { [ key ] : any ; } ; } /**
 * FluxTableMetaData Implementation.
 */ class FluxTableMetaDataImpl implements FluxTableMetaData { columns : Array < FluxTableColumn > ; constructor ( columns ) { columns . forEach ( ( col , i ) => ( col . index = i ) ) ; this . columns = columns ; } column ( label ) { for ( let i = 0 ; i < this . columns . length ; i ++ ) { const col = this . columns [ i ] ; if ( col . label === label ) return col ; } throw new IllegalArgumentError ( `Column ${ label } not found!` ) ; } toObject ( values ) { const acc = { } ; for ( let i = 0 ; i < this . columns . length && i < values . length ; i ++ ) { let val = values [ i ] ; const column = this . columns [ i ] ; if ( val === '' && column . defaultValue ) { val = column . defaultValue ; } acc [ column . label ] = ( typeSerializers [ column . dataType ] ?? identity ) ( val ) ; } return acc ; } } param columns returns export function createFluxTableMetaData ( columns ) { return new FluxTableMetaDataImpl ( columns ) ; } /** Wraps values and associated metadata of a query result row */ export interface Row { values : string [ ] ; tableMeta : FluxTableMetaData ; }