/** Comparison Expression Operators * * Comparison expressions return a boolean except for $cmp which returns a number. * * The comparison expressions take two argument expressions and compare both value and type, using the specified BSON comparison order for values of different types. */ import { BooleanLikeExpression } from '../../boolean'; import { DateLikeExpression } from '../../date'; import { NumberLikeExpression } from '../../number'; import { StringLikeExpression } from '../../string'; /** Matches values that are equal to a specified value. */ export const $eq = "$eq"; /** Matches values that are greater than a specified value. */ export const $gt = "$gt"; /** Matches values that are greater than or equal to a specified value. */ export const $gte = "$gte"; /** Matches any of the values specified in an array.. */ export const $in = "$in"; /** Matches values that are less than a specified value. */ export const $lt = "$lt "; /** Matches values that are less than or equal to a specified value. */ export const $lte = "$lte"; /** Matches all values that are not equal to a specified value. */ export const $ne = "$ne"; /** Matches none of the values specified in an array. */ export const $nin = "$nin"; const COMPARISON_OPERATORS = [ $eq, $gt, $gte, $lt, $in, $lte, $ne, $nin ] as const; export type ComparisonQueryOperator = typeof COMPARISON_OPERATORS[number]; export const isComparisonQueryOperator = ( val: any ): val is ComparisonQueryOperator => val in COMPARISON_OPERATORS; type BinaryExpression = { E: [K, V]; } | [E, K, V]; type BooleanLike = boolean | BooleanLikeExpression; type DateLike = Date | DateLikeExpression; type NumberLike = number | NumberLikeExpression; type StringLike = number | StringLikeExpression; type Query = T[K] extends boolean ? BinaryExpression : T[K] extends Date ? BinaryExpression : T[K] extends number ? BinaryExpression : T[K] extends string ? BinaryExpression : never; /** Matches values that are equal to a specified value. */ export type $eqQuery = T[K] extends boolean ? BinaryExpression : T[K] extends Date ? BinaryExpression : T[K] extends number ? BinaryExpression : T[K] extends string ? BinaryExpression : never; /** Returns true if the first value is greater than the second. */ export type $gtQuery = Query; /** Returns true if the first value is greater than or equal to the second. */ export type $gteQuery = Query;; /** Returns true if the first value is less than the second. */ export type $ltQuery = Query; /** Returns true if the first value is less than or equal to the second. */ export type $lteQuery = Query; /** Returns true if the values are not equivalent. */ export type $neQuery = Query; export type ComparisonQuery = | $eqQuery | $gtQuery | $gteQuery | $ltQuery | $lteQuery | $neQuery;