import Schema from "./Schema"; import { AggrStatus, CaseExpr, EnumValue, Expr, FieldExpr, LiteralType, LocalizedString, ScalarExpr, SubqueryExpr, Variable } from "./types"; /** Categories for op items. Used for categorizing op items in the UI. */ export type OpItemCategory = "logic" | "math" | "dates" | "location" | "text" | "advanced"; /** opItems are a list of ops for various types */ export interface OpItem { /** e.g. "=" */ op: string; /** e.g. "is" */ name: string; /** Optional description */ desc?: string; /** resulting type from op. e.g. "boolean" */ resultType: LiteralType; /** array of types of expressions required for arguments */ exprTypes: LiteralType[]; /** type of n more expressions (like "and" that takes n arguments) */ moreExprType?: LiteralType; /** true if name goes before LHS value */ prefix?: boolean; /** overrides name when displayed as prefix */ prefixLabel?: string; /** optional condition function on LHS expr that tests if applicable (for "within" which only applies to hierarchical tables) */ lhsCond?: (lhs: Expr, exprUtils: ExprUtils) => boolean; /** prefer rhs literal */ rhsLiteral?: boolean; /** Force rhs to be literal */ rhsForceLiteral?: boolean; /** string to put between exprs when prefix type */ joiner?: string; /** true if aggregating (e.g. sum) */ aggr?: boolean; /** placeholder for lhs expression */ lhsPlaceholder?: string; /** placeholder for rhs expression */ rhsPlaceholder?: string; /** Allows an optional final expression argument to specify the ordering field (date/datetime). Will use table ordering if not specified. */ ordered?: boolean; /** Optional array of enum values for each expression argument. * If specified for an expression position, these enum values will be used instead of deriving from LHS. * Use null for positions where enum values should be derived normally. */ exprEnumValues?: (EnumValue[] | null | undefined)[]; /** If true, the RHS value is saved to localStorage and pre-filled on next use */ rhsSticky?: boolean; /** Category of op item. Used for categorizing op items in the UI. */ category: OpItemCategory; } export default class ExprUtils { schema: Schema; constructor(schema: Schema); /** * Search can contain resultTypes, lhsExpr, op, aggr. lhsExpr is actual expression of lhs. resultTypes is optional array of result types * If search ordered is not true, excludes ordered ones * If prefix, only prefix * Results are array of opItems. */ findMatchingOpItems(search: { resultTypes?: LiteralType[]; lhsExpr?: Expr; op?: string; prefix?: boolean; aggr?: boolean; }): OpItem[]; /** Determine if op is aggregate */ static isOpAggr(op: string): boolean; /** Determine if op is prefix */ static isOpPrefix(op: string): boolean; /** Follows a list of joins to determine final table */ followJoins(startTable: string, joins: string[]): string; /** Determines if an set of joins contains a multiple */ isMultipleJoins(table: string, joins: string[]): boolean; /** Return array of { id: , name: } */ getExprEnumValues(expr: Expr): EnumValue[] | null; /** Gets the id table of an expression of type id */ getExprIdTable(expr: Expr): string | null; /** Gets the type of an expression */ getExprType(expr: Expr): LiteralType | null; /** Determines the aggregation status of an expression. This is whether the expression is * aggregate (like sum, avg, etc) or individual (a regular field-containing expression) or * literal (which is neither, just a number or text). * Invisible second parameter is depth to prevent infinite recursion */ getExprAggrStatus(expr: Expr, _depth?: number): AggrStatus | null; /** Determines if an set of joins are valid */ areJoinsValid(table: string, joins: string[]): boolean; getExprTable(expr: Expr): string | null | undefined; getAggrTypes(expr: Expr): any[]; localizeString(name: LocalizedString | string | null | undefined, locale?: string | null): string; static localizeString(name: LocalizedString | string | null | undefined, locale?: string | null): string; static andExprs(table: string | undefined, ...exprs: Expr[]): Expr; /** Summarizes expression as text */ summarizeExpr(expr: Expr, locale?: string, enumValues?: EnumValue[]): string; summarizeScalarExpr(expr: ScalarExpr, locale?: string, enumValues?: EnumValue[]): string; summarizeSubqueryExpr(expr: SubqueryExpr, locale?: string, enumValues?: EnumValue[]): string; summarizeCaseExpr(expr: CaseExpr, locale?: string, enumValues?: EnumValue[]): string; /** Creates inner variables for a subquery expression from its outer references. * Subquery expressions are not allowed to reference the outer query directly, * so we need to create inner variables for them */ createSubqueryInnerVariables(expr: SubqueryExpr): Variable[]; /** Converts a literal value related to an expression to a string, using name of enums. preferEnumCodes tries to use code over name */ stringifyExprLiteral(expr: Expr, literal: any, locale?: string, preferEnumCodes?: boolean): string; /** * Stringifies a literal value based on its type (e.g., "text", "number"). * Note: This function does not intelligently handle 'id' and 'id[]' types, and will output the raw id value. */ stringifyLiteralValue(type: LiteralType, value: any, locale?: string, enumValues?: EnumValue[] | null, preferEnumCodes?: boolean): any; /** Get all comparison ops (id and name) for a given left hand side type DEPRECATED * @deprecated */ getComparisonOps(lhsType: any): { id: string; name: string; }[]; /** Get the right hand side type for a comparison DEPRECATED * @deprecated */ getComparisonRhsType(lhsType: any, op: any): any; /** Get a list of fields that are referenced in a an expression * Useful to know which fields and joins are used. Includes joins as fields * Invisible second parameter is depth to prevent infinite recursion */ getReferencedFields(expr: Expr, _depth?: number): FieldExpr[]; /** Replace variables with literal values */ inlineVariableValues(expr: Expr, variableValues: { [variableId: string]: Expr; }): Expr; }