UNPKG

@convex-dev/geospatial

Version:
90 lines 3.94 kB
import type { Rectangle } from "../component/types.js"; import { GeospatialDocument, FilterValue, FilterObject } from "./index.js"; /** * A query for keys within a given shape. */ export interface GeospatialQuery<Doc extends GeospatialDocument> { /** * The shape to query. */ shape: QueryShape; /** * An optional filter expression to apply to the query. */ filter?: (q: GeospatialFilterBuilder<Doc>) => GeospatialFilterExpression<Doc>; /** * An optional limit on the number of results to return (default: 64). */ limit?: number; } interface GeospatialFilterBuilder<Doc extends GeospatialDocument> { /** * Require that a match's field equal a particular value. All conditions are ANDed together, so call * `.eq()` multiple times to further filter the set of matching documents. * * @param field The filter field. * @param value The value to match against. */ eq<FieldName extends keyof Doc["filterKeys"] & string>(field: FieldName, value: FilterValue<Doc, FieldName>): GeospatialFilterBuilder<Doc>; /** * Require that a match's field equal any of the provided values. This OR condition applies in addition * to other calls to `.eq()`. There can be at most one `.in()` call in a filter expression. * * @param field The filter field. * @param values The values to match against. */ in<FieldName extends keyof Doc["filterKeys"] & string>(field: FieldName, values: FilterValue<Doc, FieldName>[]): GeospatialFilterBuilderAfterIn<Doc>; /** * Require that a match's sort key be greater than or equal to the provided value. * * @param value The inclusive lower bound on the sort key. */ gte(field: "sortKey", value: number): GeospatialFilterBuilder<Doc>; /** * Require that a match's sort key be less than the provided value. * * @param value The exclusive upper bound on the sort key. */ lt(field: "sortKey", value: number): GeospatialFilterBuilder<Doc>; } interface GeospatialFilterBuilderAfterIn<Doc extends GeospatialDocument> { /** * Require that a match's field equal a particular value. All conditions are ANDed together, so call * `.eq()` multiple times to further filter the set of matching documents. * * @param field The filter field. * @param value The value to match against. */ eq<FieldName extends keyof Doc["filterKeys"] & string>(field: FieldName, value: FilterValue<Doc, FieldName>): GeospatialFilterBuilderAfterIn<Doc>; /** * Require that a match's sort key be greater than or equal to the provided value. * * @param value The inclusive lower bound on the sort key. */ gte(field: "sortKey", value: number): GeospatialFilterBuilderAfterIn<Doc>; /** * Require that a match's sort key be less than the provided value. * * @param value The exclusive upper bound on the sort key. */ lt(field: "sortKey", value: number): GeospatialFilterBuilderAfterIn<Doc>; } type GeospatialFilterExpression<Doc extends GeospatialDocument> = GeospatialFilterBuilder<Doc> | GeospatialFilterBuilderAfterIn<Doc>; export declare class FilterBuilderImpl<Doc extends GeospatialDocument> { filterConditions: FilterObject<Doc>[]; interval?: { startInclusive?: number; endExclusive?: number; }; inDefined: boolean; eq<FieldName extends keyof Doc["filterKeys"] & string>(field: FieldName, value: FilterValue<Doc, FieldName>): FilterBuilderImpl<Doc>; in<FieldName extends keyof Doc["filterKeys"] & string>(field: FieldName, values: FilterValue<Doc, FieldName>[]): FilterBuilderImpl<Doc>; gte(field: "sortKey", value: number): FilterBuilderImpl<Doc>; lt(field: "sortKey", value: number): FilterBuilderImpl<Doc>; } export type QueryShape = { type: "rectangle"; rectangle: Rectangle; }; export {}; //# sourceMappingURL=query.d.ts.map