UNPKG

2.13 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}
8export declare function and(filters: EntityFilter[]): CompositeFilter;
9export declare function or(filters: EntityFilter[]): CompositeFilter;
10/**
11 * A Filter is a class that contains data for a filter that can be translated
12 * into a proto when needed.
13 *
14 * @see {@link https://cloud.google.com/datastore/docs/concepts/queries#filters| Filters Reference}
15 *
16 */
17export declare abstract class EntityFilter {
18 /**
19 * Gets the proto for the filter.
20 *
21 */
22 abstract toProto(): any;
23}
24export type AllowedFilterValueType<T> = T extends '__key__' ? Key | Key[] : unknown;
25/**
26 * A PropertyFilter is a filter that gets applied to a query directly.
27 *
28 * @see {@link https://cloud.google.com/datastore/docs/concepts/queries#property_filters| Property filters Reference}
29 *
30 * @class
31 */
32export declare class PropertyFilter<T extends string> extends EntityFilter implements IFilter {
33 name: T;
34 op: Operator;
35 val: AllowedFilterValueType<T>;
36 /**
37 * Build a Property Filter object.
38 *
39 * @param {string} Property
40 * @param {Operator} operator
41 * @param {any} val
42 */
43 constructor(name: T, op: Operator, val: AllowedFilterValueType<T>);
44 /**
45 * Gets the proto for the filter.
46 *
47 */
48 toProto(): any;
49}
50/**
51 * A CompositeFilter is a filter that combines other filters and applies that
52 * combination to a query.
53 *
54 * @see {@link https://cloud.google.com/datastore/docs/concepts/queries#composite_filters| Composite filters Reference}
55 *
56 * @class
57 */
58declare class CompositeFilter extends EntityFilter {
59 filters: EntityFilter[];
60 op: string;
61 /**
62 * Build a Composite Filter object.
63 *
64 * @param {EntityFilter[]} filters
65 */
66 constructor(filters: EntityFilter[], op: CompositeOperator);
67 /**
68 * Gets the proto for the filter.
69 *
70 */
71 toProto(): any;
72}
73export declare function isFilter(filter: any): filter is EntityFilter;
74export {};