import ExprUtils from "./ExprUtils"; import Schema from "./Schema"; import { AggrStatus, Expr, LiteralType, OpExpr } from "./types"; import { OpItem } from "./ExprUtils"; export interface ValidateOptions { table?: string; types?: LiteralType[]; enumValueIds?: string[]; idTable?: string; aggrStatuses?: AggrStatus[]; } /** * Validates expressions. If an expression has been cleaned, it will always be valid. * An incomplete expression is still valid, but might return null if evaluated! */ export default class ExprValidator { schema: Schema; exprUtils: ExprUtils; constructor(schema: Schema); /** Validates an expression, returning null if it is valid, otherwise return an error string * NOTE: This uses global weak caching and assumes that expressions are never mutated after * having been validated! * options are: * table: optional current table. expression must be related to this table or will be stripped * types: optional types to limit to * enumValueIds: ids of enum values that are valid if type is enum * idTable: table that type of id must be from * aggrStatuses: statuses of aggregation to allow. list of "individual", "literal", "aggregate". Default: ["individual", "literal"] */ validateExpr(expr: Expr, options?: ValidateOptions): string | null; validateExprInternal: (expr: Expr, options: { table?: string; types?: LiteralType[]; enumValueIds?: string[]; idTable?: string; aggrStatuses?: AggrStatus[]; depth?: number; }) => string | null; /** Validates an op expression based on the chosen opItem. Returns null if valid, otherwise returns an error string */ validateOpItem(expr: OpExpr, opItem: OpItem, options: ValidateOptions): string | null; }