UNPKG

2.57 kBTypeScriptView Raw
1import { Operator, Filter as IFilter } from './query';
2import { entity } from './entity';
3import Key = entity.Key;
4declare enum CompositeOperator {
5 AND = "AND",
6 OR = "OR"
7}
8/**
9 * Returns an AND composite filter.
10 *
11 * @param {EntityFilter[]} filters The filters that make up the AND filter.
12 */
13export declare function and(filters: EntityFilter[]): CompositeFilter;
14/**
15 * Returns an OR composite filter.
16 *
17 * @param {EntityFilter[]} filters The filters that make up the OR filter.
18 */
19export declare function or(filters: EntityFilter[]): CompositeFilter;
20/**
21 * A Filter is a class that contains data for a filter that can be translated
22 * into a proto when needed.
23 *
24 * @see {@link https://cloud.google.com/datastore/docs/concepts/queries#filters| Filters Reference}
25 *
26 */
27export declare abstract class EntityFilter {
28 /**
29 * Gets the proto for the filter.
30 *
31 */
32 abstract toProto(): any;
33}
34export type AllowedFilterValueType<T> = T extends '__key__' ? Key | Key[] : unknown;
35/**
36 * A PropertyFilter is a filter that gets applied to a query directly.
37 *
38 * @see {@link https://cloud.google.com/datastore/docs/concepts/queries#property_filters| Property filters Reference}
39 *
40 * @class
41 */
42export declare class PropertyFilter<T extends string> extends EntityFilter implements IFilter {
43 name: T;
44 op: Operator;
45 val: AllowedFilterValueType<T>;
46 /**
47 * Build a Property Filter object.
48 *
49 * @param {string} Property The property name that the filter will be applied to.
50 * @param {Operator} operator The comparison operator that the filter applies.
51 * @param {any} val The value that the filter compares the property to.
52 */
53 constructor(name: T, op: Operator, val: AllowedFilterValueType<T>);
54 /**
55 * Gets the proto for the filter.
56 *
57 */
58 toProto(): any;
59}
60/**
61 * A CompositeFilter is a filter that combines other filters and applies that
62 * combination to a query.
63 *
64 * @see {@link https://cloud.google.com/datastore/docs/concepts/queries#composite_filters| Composite filters Reference}
65 *
66 * @class
67 */
68declare class CompositeFilter extends EntityFilter {
69 filters: EntityFilter[];
70 op: string;
71 /**
72 * Build a Composite Filter object.
73 *
74 * @param {EntityFilter[]} filters The filters that make up the composite filter.
75 */
76 constructor(filters: EntityFilter[], op: CompositeOperator);
77 /**
78 * Gets the proto for the filter.
79 *
80 */
81 toProto(): any;
82}
83export declare function isFilter(filter: any): filter is EntityFilter;
84export {};