import Geometry from '@arcgis/core/geometry/Geometry'; /** * Language specification of a ComplexQuery. * * @module */ /** Expression to describe a ComplexQuery. */ type ComplexQueryExpression = ShortAndExpression | LogicExpression; /** * Expression to provide a short way to specify an '$and' expression. * * ```js * { a: 1 , b: 3 } * * // this is the same like: * { $and: [{a: {$eq: 1}}, {b: {$eq:3}}]} * ``` * @internal */ interface ShortAndExpression { /** * Attribute that should match the condition. */ readonly [attributeName: string]: SimpleValue | ValueOperatorExpression | LogicExpression; } /** * '$and' operator expression. * Logical 'and' that combines other expressions. * * ```js * { $and: [{a: {$eq: 1}}, {b: {$eq:3}}]} * ``` * @internal */ interface AndExpression { /** Expression containing other expressions to be combined with 'and'. */ readonly $and: ReadonlyArray; } /** * '$or' operator expression. * Logical 'or' that combines other expressions. * ```js * { $or: [{a: {$eq: 1}}, {a: {$eq:2}}]} * ``` * @internal */ interface OrExpression { /** Expression containing other expressions to be combined with 'or'. */ readonly $or: ReadonlyArray; } /** * '$nor' operator expression. * Logical 'negating or' expression. * Semantically the same as a `$not : { $or : [...] }` combination. * * ```js * { $nor: [{a: {$eq: 1}}, {a: {$eq:2}}]} * ``` * @internal */ interface NOrExpression { /** Expression containing other expressions to be combined with 'negating or'. */ readonly $nor: ReadonlyArray; } /** * '$not' operator expression. * Logically negates another expression. * * ```js * { $not: {a: {$eq: 1} } } * ``` * @internal */ interface NotExpression { /** Expression to be negated. */ readonly $not: ComplexQueryExpression; } /** * '$eq' operator expression. * Tests for an attribute to equal a given value. * * ```js * {a: {$eq: 1} } * ``` * The short form is `{a: 1}`. * @internal */ interface EqualsExpression { /** Value to be checked against for equality. */ readonly $eq: SimpleValue; } /** * '$eqw' operator expression. * Tests for an attribute to match a wildcard expression. * Allowed wild cards are '*' (any char) and '?' (single char). * * ```js * {a: {$eqw: "H*lo"} } * ``` * @internal */ interface EqualsWildCardExpression { /** The value containing the wild card. */ readonly $eqw: string; } /** * '$lt' operator expression. * Tests for an attribute to be lesser than a given value. * * ```js * {a: {$lt: 4} } * ``` * @internal */ interface LesserExpression { /** Value to check against. */ readonly $lt: SimpleValue; } /** * '$lte' operator expression. * Tests for an attribute to be lesser or equal to a given value. * * ```js * {a: {$lte: 4} } * ``` * @internal */ interface LesserOrEqualExpression { /** Value to check against. */ readonly $lte: SimpleValue; } /** * '$gt' operator expression. * Tests for an attribute to be greater than a given value. * * ```js * {a: {$gt: 4} } * ``` * @internal */ interface GreaterExpression { /** Value to check against. */ readonly $gt: SimpleValue; } /** * '$gte' operator expression. * Tests for an attribute to be greater or equal to a given value. * * ```js * {a: {$gte: 4} } * ``` * @internal */ interface GreaterOrEqual { /** Value to check against. */ readonly $gte: SimpleValue; } /** * '$in' operator expression. * Tests for an attribute to be equal to at least one value in a list of values. * * ```js * {a: {$in: [1,2,3,4]} } * ``` * This is semantically equivalent to: * ```js * {$or: [{a:{$eq:1}},{a:{$eq:2}},{a:{$eq:3}},{a:{$eq:4}}]}} * ``` * @internal */ interface InExpression { /** List of values to check against. */ readonly $in: ReadonlyArray; } /** * '$nin' operator expression. * Tests for an attribute not to be equal to any of the values in a list of values. * * ```js * {a: {$nin: [1,2,3,4]} } * ``` * This is semantically equivalent to: * ```js * {$not:{$or: [{a:{$eq:1}},{a:{$eq:2}},{a:{$eq:3}},{a:{$eq:4}}]}}} * ``` * @internal */ interface NotInExpression { /** List of values to check against. */ readonly $nin: ReadonlyArray; } /** * '$neq' operator expression. * Tests for an attribute not to be equal to a value. * * ```js * {a: {$neq: 1} } * ``` * This is semantically equivalent to: * ```js * {$not: {a: {$eq: 1}}} * ``` * @internal */ interface NotEqualExpression { /** Value to check against. */ readonly $neq: SimpleValue; } /** * '$exists' operator expression. * Tests for an attribute to exist or not exist, depending on the boolean flag given. * * ```js * {a: {$exists: true} } * ``` * @internal */ interface ExistsExpression { /** Flag to determine if a value exists or not. */ readonly $exists: boolean; } /** * '$suggest' operator expression. * Tests if an attribute value may be suggested by the given string. * * ```js * {a: {$suggest: "term"} } * ``` * @internal */ interface SuggestExpression { /** Suggest term for an attribute value. */ readonly $suggest: string; } /** * '$elemMatch' operator expression. * Only valid if an attribute has an array as value. * Tests for at least one element in the array to fulfill the given expression. * * ```js * {a:{$elemMatch: {name:{$eq: "x"}}}} * ``` * @internal */ interface ElementMatchExpression { /** Expression to check against. */ readonly $elemMatch: ReadonlyArray; } /** * '$intersects' spatial operator expression. * Operator matches if attribute `geometry` intersects the given geometry. * * ```js * { geometry : { $intersects: testGeometry }} * ``` * @internal */ interface SpatialIntersectsExpression { /** Test geometry */ readonly $intersects: Geometry; } /** * '$contains' spatial operator expression. * Operator matches if attribute `geometry` is contained inside the given container geometry. * * ```js * { geometry : { $contains: containerGeometry }} * ``` * @internal */ interface SpatialContainsExpression { /** Test geometry */ readonly $contains: Geometry; } /** * '$crosses' spatial operator expression. * Operator matches if attribute `geometry` crosses the other geometry. * * ```js * { geometry : { $crosses: testGeometry }} * ``` * @internal */ interface SpatialCrossesExpression { /** Test geometry */ readonly $crosses: Geometry; } /** * '$envelope-intersects' spatial operator expression. * Operator matches if envelope of attribute `geometry` intersects envelope of other geometry. * * ```js * { geometry : { $envelope-intersects: testGeometry }} * ``` * @internal */ interface SpatialEnvelopeIntersectsExpression { /** Test geometry */ readonly "$envelope-intersects": Geometry; } /** * '$overlaps' spatial operator expression. * Operator matches if attribute `geometry` overlaps the other geometry. * * ```js * { geometry : { $overlaps: testGeometry }} * ``` * @internal */ interface SpatialOverlapsExpression { /** Test geometry */ readonly "$overlaps": Geometry; } /** * '$touches' spatial operator expression. * Operator matches if attribute `geometry` touches the other geometry (share a common boundary). * * ```js * { geometry : { $touches: testGeometry }} * ``` * @internal */ interface SpatialTouchesExpression { /** Test geometry */ readonly "$touches": Geometry; } /** * '$within' spatial operator expression. * The opposite of `$contains`. * * Operator matches if attribute `geometry` contains the other geometry * (Alternative spelling: other geometry is within attribute `geometry`). * * ```js * { geometry : { $within: testGeometry }} * ``` * @internal */ interface SpatialWithinExpression { /** Test geometry */ readonly "$within": Geometry; } /** Logical expressions to combine other expressions. * @internal */ type LogicExpression = NotExpression | AndExpression | OrExpression | NOrExpression; type SpatialOperatorExpression = SpatialIntersectsExpression | SpatialContainsExpression | SpatialCrossesExpression | SpatialEnvelopeIntersectsExpression | SpatialOverlapsExpression | SpatialTouchesExpression | SpatialWithinExpression; /** Value operator expressions to check attribute values against. * @internal */ type ValueOperatorExpression = EqualsExpression | EqualsWildCardExpression | LesserExpression | LesserOrEqualExpression | GreaterExpression | GreaterOrEqual | InExpression | NotInExpression | NotEqualExpression | ExistsExpression | SuggestExpression | ElementMatchExpression | SpatialOperatorExpression; /** Allowed types for simple values. * @internal */ type SimpleValue = string | number | boolean | Date | RegExp | null | undefined | any[] | Record; export type { AndExpression, ComplexQueryExpression, ElementMatchExpression, EqualsExpression, EqualsWildCardExpression, ExistsExpression, GreaterExpression, GreaterOrEqual, InExpression, LesserExpression, LesserOrEqualExpression, LogicExpression, NOrExpression, NotEqualExpression, NotExpression, NotInExpression, OrExpression, ShortAndExpression, SpatialContainsExpression, SpatialCrossesExpression, SpatialEnvelopeIntersectsExpression, SpatialIntersectsExpression, SpatialOperatorExpression, SpatialOverlapsExpression, SpatialTouchesExpression, SpatialWithinExpression, SuggestExpression, ValueOperatorExpression };