import type { AgAggregationFunction } from './agAggregationFunction'; import type { AgDataType, InferPrimitive, InferSerializable, Maybe } from './agDataType'; import type { InferDataTypeFromFormat } from './agFormat'; import type { AgFormats } from './agFormats'; import type { AgStudioCommon } from './agStudioCommon'; export type AgFieldRole = 'category' | 'temporal' | 'numeric'; export type AgFieldCardinality = 'low' | 'medium' | 'high'; export type AgFormat = 'integerFormat' | 'decimalFormat' | 'percentageFormat' | 'currencyFormat' | 'textFormat' | 'dateFormat' | 'dateTimeFormat' | 'booleanFormat'; export type AgFieldDataAccessor = keyof TData | ((row: TData) => Maybe>); export interface AgBaseFieldDefinition { /** Field ID. */ id: string; /** Display name. */ name?: string; /** Field description. Displayed in the Field Panel */ description?: string; /** Set to `true` to hide from being selected in the UI. Field can still be used for joins. */ hide?: boolean; /** Optional. How the field values will be serialized into state. Defaults to format serializer. */ serializer?: AgFieldSerializer>; /** Optional. How the field values will be deserialized from state. Defaults to format deserializer. */ deserializer?: AgFieldDeserializer>; /** Optional. How the field values will be displayed. Defaults to format value formatter. */ valueFormatter?: AgFieldValueFormatter, TOptions>; /** Optional. How blank values will be displayed. Defaults to format blank value. */ blankValue?: string; /** Optional. Will be passed to the value formatter. */ options?: TOptions; } export interface AgFieldDefinition extends AgBaseFieldDefinition { /** The format type of the field (provides default formatting, etc.). */ format: TFormat; /** Optional. How to retrieve the value from the data. Either the property key, or a callback. If undefined, `id` will be used as the property key. */ accessor?: AgFieldDataAccessor>; /** Optional. Cardinality of the field data. Improves performance if provided. */ cardinality?: AgFieldCardinality; /** Optional. Does the field contain blank values. Improves performance if provided. */ notBlank?: boolean; } export interface AgWidgetFieldReference { id: string; aggregation?: AgAggregationFunction; } export type AgFieldSerializer = (value: Maybe>) => Maybe>; export type AgFieldDeserializer = (value: Maybe>) => Maybe>; export interface AgFieldValueFormatterParams extends AgStudioCommon { value: InferPrimitive; options: TOptions | undefined; field: AgWidgetFieldReference; } export type AgFieldValueFormatter = (params: AgFieldValueFormatterParams) => string;