UNPKG

@firebase/firestore

Version:

The Cloud Firestore component of the Firebase JS SDK.

77 lines (76 loc) 3.43 kB
/** * @license * Copyright 2022 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { Target } from '../core/target'; import { FieldIndex } from './field_index'; /** * A light query planner for Firestore. * * This class matches a `FieldIndex` against a Firestore Query `Target`. It * determines whether a given index can be used to serve the specified target. * * The following table showcases some possible index configurations: * * Query | Index * ----------------------------------------------------------------------------- * where('a', '==', 'a').where('b', '==', 'b') | a ASC, b DESC * where('a', '==', 'a').where('b', '==', 'b') | a ASC * where('a', '==', 'a').where('b', '==', 'b') | b DESC * where('a', '>=', 'a').orderBy('a') | a ASC * where('a', '>=', 'a').orderBy('a', 'desc') | a DESC * where('a', '>=', 'a').orderBy('a').orderBy('b') | a ASC, b ASC * where('a', '>=', 'a').orderBy('a').orderBy('b') | a ASC * where('a', 'array-contains', 'a').orderBy('b') | a CONTAINS, b ASCENDING * where('a', 'array-contains', 'a').orderBy('b') | a CONTAINS */ export declare class TargetIndexMatcher { private readonly collectionId; private inequalityFilters; private readonly equalityFilters; private readonly orderBys; constructor(target: Target); get hasMultipleInequality(): boolean; /** * Returns whether the index can be used to serve the TargetIndexMatcher's * target. * * An index is considered capable of serving the target when: * - The target uses all index segments for its filters and orderBy clauses. * The target can have additional filter and orderBy clauses, but not * fewer. * - If an ArrayContains/ArrayContainsAnyfilter is used, the index must also * have a corresponding `CONTAINS` segment. * - All directional index segments can be mapped to the target as a series of * equality filters, a single inequality filter and a series of orderBy * clauses. * - The segments that represent the equality filters may appear out of order. * - The optional segment for the inequality filter must appear after all * equality segments. * - The segments that represent that orderBy clause of the target must appear * in order after all equality and inequality segments. Single orderBy * clauses cannot be skipped, but a continuous orderBy suffix may be * omitted. */ servedByIndex(index: FieldIndex): boolean; /** * Returns a full matched field index for this target. Currently multiple * inequality query is not supported so function returns null. */ buildTargetIndex(): FieldIndex | null; private hasMatchingEqualityFilter; private matchesFilter; private matchesOrderBy; }