import type { AgAggregationFunction } from './agAggregationFunction'; import type { Maybe } from './agDataType'; import type { AgBaseFieldDefinition, AgFormat } from './agFieldDefinition'; import type { AgFormats } from './agFormats'; export interface AgExpressionOperatorTypes { /** * Add two values together. * - `['number', 'number'] => 'number'` * - `['string', 'string'] => 'string'` */ add: AgFunctionExpression; /** * Subtract the second value from the first. * - `['number', 'number'] => 'number'` */ subtract: AgFunctionExpression; /** * Multiply two values together. * - `['number', 'number'] => 'number'` */ multiply: AgFunctionExpression; /** * Divide the first value by the second. * - `['number', 'number'] => 'number'` */ divide: AgFunctionExpression; /** * Remainder of the first value divided by the second. * - `['number', 'number'] => 'number'` */ modulo: AgFunctionExpression; /** * Are the two values equal? * - `['number', 'number'] => 'boolean'` * - `['date', 'date'] => 'boolean'` * - `['datetime', 'datetime'] => 'boolean'` * - `['boolean', 'boolean'] => 'boolean'` * - `['string', 'string'] => 'boolean'` */ equals: AgFunctionExpression; /** * Are the two values not equal? * - `['number', 'number'] => 'boolean'` * - `['date', 'date'] => 'boolean'` * - `['datetime', 'datetime'] => 'boolean'` * - `['boolean', 'boolean'] => 'boolean'` * - `['string', 'string'] => 'boolean'` */ notEqual: AgFunctionExpression; /** * Is the first value less than the second? * - `['number', 'number'] => 'boolean'` */ lessThan: AgFunctionExpression; /** * Is the first value greater than the second? * - `['number', 'number'] => 'boolean'` */ greaterThan: AgFunctionExpression; /** * Is the first value less than or equal to the second? * - `['number', 'number'] => 'boolean'` */ lessThanOrEqual: AgFunctionExpression; /** * Is the first value greater than or equal to the second? * - `['number', 'number'] => 'boolean'` */ greaterThanOrEqual: AgFunctionExpression; /** * Are both the values true? * - `['boolean', 'boolean'] => 'boolean'` */ and: AgFunctionExpression; /** * Are either of the values true? * - `['boolean', 'boolean'] => 'boolean'` */ or: AgFunctionExpression; /** * Negates the value. * - `['boolean'] => 'boolean'` */ not: AgFunctionExpression; /** * Negates the value. * - `['number'] => 'number'` */ negate: AgFunctionExpression; /** * If the first value is true then return the second value, else return the third value. * - `['boolean', 'string', 'string'] => 'string'` * - `['boolean', 'number', 'number'] => 'number'` * - `['boolean', 'boolean', 'boolean'] => 'boolean'` * - `['boolean', 'date', 'date'] => 'date'` * - `['boolean', 'datetime', 'datetime'] => 'datetime'` */ if: AgFunctionExpression; /** * Is the first value in any of the subsequent values? * - `['string', ...'string'] => 'boolean'` * - `['number', ...'number'] => 'boolean'` * - `['boolean', ...'boolean'] => 'boolean'` * - `['date', ...'date'] => 'boolean'` * - `['datetime', ...'datetime'] => 'boolean'` */ in: AgFunctionExpression; /** * Is the value true? * - `['boolean'] => 'boolean'` */ isTrue: AgFunctionExpression; /** * Is the value false? * - `['boolean'] => 'boolean'` */ isFalse: AgFunctionExpression; /** * Is the value null? * - `['string'] => 'boolean'` * - `['number'] => 'boolean'` * - `['boolean'] => 'boolean'` * - `['date'] => 'boolean'` * - `['datetime'] => 'boolean'` */ isNull: AgFunctionExpression; /** * Is the value not null? * - `['string'] => 'boolean'` * - `['number'] => 'boolean'` * - `['boolean'] => 'boolean'` * - `['date'] => 'boolean'` * - `['datetime'] => 'boolean'` */ isNotNull: AgFunctionExpression; /** * Return the number of units defined by the first value that are between the second and third values. * - ['string', 'date', 'date'] => number * - ['string', 'datetime', 'datetime'] => number * * Supported units: * - Milliseconds - `'millisecond' | 'ms'` * - Seconds - `'second' | 'ss' | 's'` * - Minutes - `'minute' | 'mi' | 'n'` * - Hours - `'hour' | 'hh'` * - Days - `'day' | 'dy' | 'y'` * - Weeks - `'week' | 'ww' | 'wk'` * - Weekdays - `'weekday' | 'dw' | 'w'` * - Months - `'month' | 'mm' | 'm'` * - Quarters -`'quarter' | 'qq' | 'q'` * - Years - `'year' | 'yyyy' | 'yy'` * - Days of year - `'dayofyear'` */ datediff: AgFunctionExpression; } export interface AgFunctionExpression { operator: TExpressionOperatorType; inputs: AgExpression[]; } export interface AgNumberValueExpression { type: 'number'; value: Maybe; } export interface AgStringValueExpression { type: 'string'; value: Maybe; } export interface AgBooleanValueExpression { type: 'boolean'; value: Maybe; } export interface AgDateValueExpression { type: 'date'; /** string is ISO-8610 format, number is epoch value */ value: Maybe; } export interface AgDateTimeValueExpression { type: 'datetime'; /** string is ISO-8610 format, number is epoch value */ value: Maybe; } /** Used for docs interface generation */ export interface FakeAgExpression { /** A value expression is a fixed value (e.g. number, string, etc.). */ valueExpression: AgValueExpression; /** * A function expression applies an operator to one or more inputs. * * Each input is another expression - a function, value or field. */ functionExpression: AgFunctionExpression; /** A field expression refers to another field (either in the source data, or another expression field). */ fieldExpression: AgFieldExpression; } export type AgValueExpression = AgStringValueExpression | AgNumberValueExpression | AgBooleanValueExpression | AgDateValueExpression | AgDateTimeValueExpression; export interface AgFieldExpression { /** Source field ID (tableId.fieldId) or expression field ID */ id: string; aggregation?: AgAggregationFunction; } export type AgExpression = AgFunctionExpression | AgValueExpression | AgFieldExpression; export interface AgExpressionFieldDefinition extends AgBaseFieldDefinition { /** * The format type of the field (provides default formatting, etc.). * If not provided, will be inferred from the expression. */ format?: TFormat; /** * Whether this expression creates a Measure or a Calculated Column. * A Calculated Column produces a list of values, e.g. quantity × cost, even without a grouping. * A Measure produces a single value e.g. SUM(quantity). */ isMeasure: boolean; /** The expression for the field. */ expression: AgExpression; }