import { $eq, $gt, $gte, $in, $lt, $lte, $ne, $nin } from './query/comparison'; import { $exists } from './query/element'; import { $and, $nor, $not, $or } from './query/logical'; type Logical = { [$and]?: Array>; [$nor]?: Array>; [$not]?: Constraint | Array>; [$or]?: Array>; }; export type ComparisonObject = | { [$eq]: T; } | { [$exists]: boolean; } | { [$gt]: T; } | { [$gt]: T;[$lt]: T; } | { [$gt]: T;[$lte]: T; } | { [$gte]: T; } | { [$gte]: T;[$lt]: T; } | { [$gte]: T;[$lte]: T; } | { [$in]: T[]; } | { [$lt]: T; } | { [$lte]: T; } | { [$ne]: T;[$exists]?: true; } | { [$nin]: T[];[$exists]?: true; }; export type ComparisonTuple = | [typeof $exists, boolean] | [typeof $eq, T] | [typeof $gt, T] | [typeof $gte, T] | [typeof $in, ...T[]] | [typeof $lt, T] | [typeof $lte, T] | [typeof $ne, T] | [typeof $nin, ...T[]]; export type Comparison = ComparisonTuple | ComparisonObject; export type ConstraintTuple = | [typeof $exists, P, boolean] | [typeof $eq, P, T[P]] | [typeof $gt, P, T[P]] | [typeof $gte, P, T[P]] | [typeof $in, P, T[P], ...T[P][]] | [typeof $lt, P, T[P]] | [typeof $lte, P, T[P]] | [typeof $ne, P, T[P]] | [typeof $nin, P, T[P], ...T[P][]]; export type Constraint = { [P in keyof T]?: Comparison | typeof $exists | AltConstraint; } | Logical | ConstraintTuple; export type AltConstraint = AltLogical | AltLogicalTuple | ComparisonTuple | AltConstraintTuple; export type AltConstraintTuple = | [typeof $exists, T, boolean] | [typeof $eq, T] | [typeof $gt, T] | [typeof $gte, T] | [typeof $in, T, ...T[]] | [typeof $lt, T] | [typeof $lte, T] | [typeof $ne, T] | [typeof $nin, T, ...T[]]; export type AltLogical = { [$and]?: Array>; [$nor]?: Array>; [$not]?: AltConstraint | Array>; [$or]?: Array>; }; export type AltLogicalTuple = | [AltConstraint, ...AltConstraint[]] // same as $and | [typeof $and, AltConstraint, ...AltConstraint[]] | [typeof $nor, AltConstraint, ...AltConstraint[]] | [typeof $not, AltConstraint, ...AltConstraint[]] | [typeof $or, AltConstraint, ...AltConstraint[]];