UNPKG

@firebase/firestore

Version:

The Cloud Firestore component of the Firebase JS SDK.

1,486 lines (1,456 loc) 734 kB
/** * @license * Copyright 2020 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. */ interface VersionService { library: string; version: string; } interface PlatformLoggerService { getPlatformInfoString(): string; } interface HeartbeatService { /** * Called to report a heartbeat. The function will generate * a HeartbeatsByUserAgent object, update heartbeatsCache, and persist it * to IndexedDB. * Note that we only store one heartbeat per day. So if a heartbeat for today is * already logged, subsequent calls to this function in the same day will be ignored. */ triggerHeartbeat(): Promise<void>; /** * Returns a base64 encoded string which can be attached to the heartbeat-specific header directly. * It also clears all heartbeats from memory as well as in IndexedDB. */ getHeartbeatsHeader(): Promise<string>; } /** * @license * Copyright 2020 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. */ /** * A {@link @firebase/app#FirebaseApp} holds the initialization information for a collection of * services. * * Do not call this constructor directly. Instead, use * {@link (initializeApp:1) | initializeApp()} to create an app. * * @public */ interface FirebaseApp { /** * The (read-only) name for this app. * * The default app's name is `"[DEFAULT]"`. * * @example * ```javascript * // The default app's name is "[DEFAULT]" * const app = initializeApp(defaultAppConfig); * console.log(app.name); // "[DEFAULT]" * ``` * * @example * ```javascript * // A named app's name is what you provide to initializeApp() * const otherApp = initializeApp(otherAppConfig, "other"); * console.log(otherApp.name); // "other" * ``` */ readonly name: string; /** * The (read-only) configuration options for this app. These are the original * parameters given in {@link (initializeApp:1) | initializeApp()}. * * @example * ```javascript * const app = initializeApp(config); * console.log(app.options.databaseURL === config.databaseURL); // true * ``` */ readonly options: FirebaseOptions; /** * The settable config flag for GDPR opt-in/opt-out */ automaticDataCollectionEnabled: boolean; } /** * @public * * Firebase configuration object. Contains a set of parameters required by * services in order to successfully communicate with Firebase server APIs * and to associate client data with your Firebase project and * Firebase application. Typically this object is populated by the Firebase * console at project setup. See also: * {@link https://firebase.google.com/docs/web/setup#config-object | Learn about the Firebase config object}. */ interface FirebaseOptions { /** * An encrypted string used when calling certain APIs that don't need to * access private user data * (example value: `AIzaSyDOCAbC123dEf456GhI789jKl012-MnO`). */ apiKey?: string; /** * Auth domain for the project ID. */ authDomain?: string; /** * Default Realtime Database URL. */ databaseURL?: string; /** * The unique identifier for the project across all of Firebase and * Google Cloud. */ projectId?: string; /** * The default Cloud Storage bucket name. */ storageBucket?: string; /** * Unique numerical value used to identify each sender that can send * Firebase Cloud Messaging messages to client apps. */ messagingSenderId?: string; /** * Unique identifier for the app. */ appId?: string; /** * An ID automatically created when you enable Analytics in your * Firebase project and register a web app. In versions 7.20.0 * and higher, this parameter is optional. */ measurementId?: string; } /** * @internal */ interface _FirebaseService { app: FirebaseApp; /** * Delete the service and free it's resources - called from * {@link @firebase/app#deleteApp | deleteApp()} */ _delete(): Promise<void>; } declare module '@firebase/component' { interface NameServiceMapping { 'app': FirebaseApp; 'app-version': VersionService; 'heartbeat': HeartbeatService; 'platform-logger': PlatformLoggerService; } } /** * @license * Copyright 2017 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. */ type LogLevelString = 'debug' | 'verbose' | 'info' | 'warn' | 'error' | 'silent'; /** * An object that can be injected into the environment as __FIREBASE_DEFAULTS__, * either as a property of globalThis, a shell environment variable, or a * cookie. * * This object can be used to automatically configure and initialize * a Firebase app as well as any emulators. * * @public */ interface FirebaseDefaults { config?: Record<string, string>; emulatorHosts?: Record<string, string>; _authTokenSyncURL?: string; _authIdTokenMaxAge?: number; /** * Override Firebase's runtime environment detection and * force the SDK to act as if it were in the specified environment. */ forceEnvironment?: 'browser' | 'node'; [key: string]: unknown; } declare global { var __FIREBASE_DEFAULTS__: FirebaseDefaults | undefined; } /** * @license * Copyright 2021 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. */ type FirebaseSignInProvider = 'custom' | 'email' | 'password' | 'phone' | 'anonymous' | 'google.com' | 'facebook.com' | 'github.com' | 'twitter.com' | 'microsoft.com' | 'apple.com'; interface FirebaseIdToken { iss: string; aud: string; sub: string; iat: number; exp: number; user_id: string; auth_time: number; provider_id?: 'anonymous'; email?: string; email_verified?: boolean; phone_number?: string; name?: string; picture?: string; firebase: { sign_in_provider: FirebaseSignInProvider; identities?: { [provider in FirebaseSignInProvider]?: string[]; }; }; [claim: string]: unknown; uid?: never; } type EmulatorMockTokenOptions = ({ user_id: string; } | { sub: string; }) & Partial<FirebaseIdToken>; declare class FirebaseError extends Error { /** The error code for this error. */ readonly code: string; /** Custom data for this error. */ customData?: Record<string, unknown> | undefined; /** The custom name for all FirebaseErrors. */ readonly name: string; constructor( /** The error code for this error. */ code: string, message: string, /** Custom data for this error. */ customData?: Record<string, unknown> | undefined); } /** * @license * Copyright 2023 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. */ /** * Options that configure the SDK’s underlying network transport (WebChannel) * when long-polling is used. * * Note: This interface is "experimental" and is subject to change. * * See `FirestoreSettings.experimentalAutoDetectLongPolling`, * `FirestoreSettings.experimentalForceLongPolling`, and * `FirestoreSettings.experimentalLongPollingOptions`. */ interface ExperimentalLongPollingOptions { /** * The desired maximum timeout interval, in seconds, to complete a * long-polling GET response. Valid values are between 5 and 30, inclusive. * Floating point values are allowed and will be rounded to the nearest * millisecond. * * By default, when long-polling is used the "hanging GET" request sent by * the client times out after 30 seconds. To request a different timeout * from the server, set this setting with the desired timeout. * * Changing the default timeout may be useful, for example, if the buffering * proxy that necessitated enabling long-polling in the first place has a * shorter timeout for hanging GET requests, in which case setting the * long-polling timeout to a shorter value, such as 25 seconds, may fix * prematurely-closed hanging GET requests. * For example, see https://github.com/firebase/firebase-js-sdk/issues/6987. */ timeoutSeconds?: number; } /** * @license * Copyright 2017 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. */ declare class DatabaseInfo { readonly databaseId: DatabaseId; readonly appId: string; readonly persistenceKey: string; readonly host: string; readonly ssl: boolean; readonly forceLongPolling: boolean; readonly autoDetectLongPolling: boolean; readonly longPollingOptions: ExperimentalLongPollingOptions; readonly useFetchStreams: boolean; readonly isUsingEmulator: boolean; readonly apiKey: string | undefined; /** * Constructs a DatabaseInfo using the provided host, databaseId and * persistenceKey. * * @param databaseId - The database to use. * @param appId - The Firebase App Id. * @param persistenceKey - A unique identifier for this Firestore's local * storage (used in conjunction with the databaseId). * @param host - The Firestore backend host to connect to. * @param ssl - Whether to use SSL when connecting. * @param forceLongPolling - Whether to use the forceLongPolling option * when using WebChannel as the network transport. * @param autoDetectLongPolling - Whether to use the detectBufferingProxy * option when using WebChannel as the network transport. * @param longPollingOptions - Options that configure long-polling. * @param useFetchStreams - Whether to use the Fetch API instead of * XMLHTTPRequest */ constructor(databaseId: DatabaseId, appId: string, persistenceKey: string, host: string, ssl: boolean, forceLongPolling: boolean, autoDetectLongPolling: boolean, longPollingOptions: ExperimentalLongPollingOptions, useFetchStreams: boolean, isUsingEmulator: boolean, apiKey: string | undefined); } /** * Represents the database ID a Firestore client is associated with. * @internal */ declare class DatabaseId { readonly projectId: string; readonly database: string; constructor(projectId: string, database?: string); static empty(): DatabaseId; get isDefaultDatabase(): boolean; isEqual(other: {}): boolean; } interface ApiClientObjectMap<T> { [k: string]: T; } declare type Timestamp$1 = string | { seconds?: string | number; nanos?: number; }; declare type CompositeFilterOp = 'OPERATOR_UNSPECIFIED' | 'AND' | 'OR'; declare type FieldFilterOp = 'OPERATOR_UNSPECIFIED' | 'LESS_THAN' | 'LESS_THAN_OR_EQUAL' | 'GREATER_THAN' | 'GREATER_THAN_OR_EQUAL' | 'EQUAL' | 'NOT_EQUAL' | 'ARRAY_CONTAINS' | 'IN' | 'ARRAY_CONTAINS_ANY' | 'NOT_IN'; declare type FieldTransformSetToServerValue = 'SERVER_VALUE_UNSPECIFIED' | 'REQUEST_TIME'; declare type IndexFieldMode = 'MODE_UNSPECIFIED' | 'ASCENDING' | 'DESCENDING'; declare type IndexState$1 = 'STATE_UNSPECIFIED' | 'CREATING' | 'READY' | 'ERROR'; declare type OrderDirection = 'DIRECTION_UNSPECIFIED' | 'ASCENDING' | 'DESCENDING'; declare type TargetChangeTargetChangeType = 'NO_CHANGE' | 'ADD' | 'REMOVE' | 'CURRENT' | 'RESET'; declare type UnaryFilterOp = 'OPERATOR_UNSPECIFIED' | 'IS_NAN' | 'IS_NULL' | 'IS_NOT_NAN' | 'IS_NOT_NULL'; declare type ValueNullValue = 'NULL_VALUE'; declare namespace firestoreV1ApiClientInterfaces { interface Aggregation { count?: Count; sum?: Sum; avg?: Avg; alias?: string; } interface AggregationResult { aggregateFields?: ApiClientObjectMap<Value>; } interface ArrayValue { values?: Value[]; } interface Avg { field?: FieldReference; } interface BatchGetDocumentsRequest { database?: string; documents?: string[]; mask?: DocumentMask; transaction?: string; newTransaction?: TransactionOptions; readTime?: string; } interface BatchGetDocumentsResponse { found?: Document; missing?: string; transaction?: string; readTime?: string; } interface BeginTransactionRequest { options?: TransactionOptions; } interface BeginTransactionResponse { transaction?: string; } interface BitSequence { bitmap?: string | Uint8Array; padding?: number; } interface BloomFilter { bits?: BitSequence; hashCount?: number; } interface CollectionSelector { collectionId?: string; allDescendants?: boolean; } interface CommitRequest { database?: string; writes?: Write[]; transaction?: string; } interface CommitResponse { writeResults?: WriteResult[]; commitTime?: string; } interface CompositeFilter { op?: CompositeFilterOp; filters?: Filter[]; } interface Count { upTo?: number; } interface Cursor { values?: Value[]; before?: boolean; } interface Document { name?: string; fields?: ApiClientObjectMap<Value>; createTime?: Timestamp$1; updateTime?: Timestamp$1; } interface DocumentChange { document?: Document; targetIds?: number[]; removedTargetIds?: number[]; } interface DocumentDelete { document?: string; removedTargetIds?: number[]; readTime?: Timestamp$1; } interface DocumentMask { fieldPaths?: string[]; } interface DocumentRemove { document?: string; removedTargetIds?: number[]; readTime?: string; } interface DocumentTransform { document?: string; fieldTransforms?: FieldTransform[]; } interface DocumentsTarget { documents?: string[]; } interface Empty { } interface ExecutePipelineRequest { database?: string; structuredPipeline?: StructuredPipeline; transaction?: string; newTransaction?: TransactionOptions; readTime?: string; } interface ExecutePipelineResponse { transaction?: string; results?: Document[]; executionTime?: string; } interface ExistenceFilter { targetId?: number; count?: number; unchangedNames?: BloomFilter; } interface FieldFilter { field?: FieldReference; op?: FieldFilterOp; value?: Value; } interface FieldReference { fieldPath?: string; } interface FieldTransform { fieldPath?: string; setToServerValue?: FieldTransformSetToServerValue; appendMissingElements?: ArrayValue; removeAllFromArray?: ArrayValue; increment?: Value; } interface Filter { compositeFilter?: CompositeFilter; fieldFilter?: FieldFilter; unaryFilter?: UnaryFilter; } interface Function { name?: string; args?: Value[]; options?: ApiClientObjectMap<Value>; } interface Index { name?: string; collectionId?: string; fields?: IndexField[]; state?: IndexState$1; } interface IndexField { fieldPath?: string; mode?: IndexFieldMode; } interface LatLng { latitude?: number; longitude?: number; } interface ListCollectionIdsRequest { pageSize?: number; pageToken?: string; } interface ListCollectionIdsResponse { collectionIds?: string[]; nextPageToken?: string; } interface ListDocumentsResponse { documents?: Document[]; nextPageToken?: string; } interface ListIndexesResponse { indexes?: Index[]; nextPageToken?: string; } interface ListenRequest { addTarget?: Target; removeTarget?: number; labels?: ApiClientObjectMap<string>; } interface ListenResponse { targetChange?: TargetChange; documentChange?: DocumentChange; documentDelete?: DocumentDelete; documentRemove?: DocumentRemove; filter?: ExistenceFilter; } interface MapValue { fields?: ApiClientObjectMap<Value>; } interface Operation { name?: string; metadata?: ApiClientObjectMap<any>; done?: boolean; error?: Status; response?: ApiClientObjectMap<any>; } interface Order { field?: FieldReference; direction?: OrderDirection; } interface Pipeline { stages?: Stage[]; } interface Precondition { exists?: boolean; updateTime?: Timestamp$1; } interface Projection { fields?: FieldReference[]; } interface QueryTarget { parent?: string; structuredQuery?: StructuredQuery; } interface ReadOnly { readTime?: string; } interface ReadWrite { retryTransaction?: string; } interface RollbackRequest { transaction?: string; } interface RunQueryRequest { parent?: string; structuredQuery?: StructuredQuery; transaction?: string; newTransaction?: TransactionOptions; readTime?: string; } interface RunQueryResponse { transaction?: string; document?: Document; readTime?: string; skippedResults?: number; } interface RunAggregationQueryRequest { parent?: string; structuredAggregationQuery?: StructuredAggregationQuery; transaction?: string; newTransaction?: TransactionOptions; readTime?: string; } interface RunAggregationQueryResponse { result?: AggregationResult; transaction?: string; readTime?: string; } interface StructuredAggregationQuery { structuredQuery?: StructuredQuery; aggregations?: Aggregation[]; } interface Stage { name?: string; args?: Value[]; options?: ApiClientObjectMap<Value>; } interface Status { code?: number; message?: string; details?: Array<ApiClientObjectMap<any>>; } interface StructuredPipeline { pipeline?: Pipeline; options?: ApiClientObjectMap<Value>; } interface StructuredQuery { select?: Projection; from?: CollectionSelector[]; where?: Filter; orderBy?: Order[]; startAt?: Cursor; endAt?: Cursor; offset?: number; limit?: number | { value: number; }; } interface Sum { field?: FieldReference; } interface Target { query?: QueryTarget; documents?: DocumentsTarget; resumeToken?: string | Uint8Array; readTime?: Timestamp$1; targetId?: number; once?: boolean; expectedCount?: number | { value: number; }; } interface TargetChange { targetChangeType?: TargetChangeTargetChangeType; targetIds?: number[]; cause?: Status; resumeToken?: string | Uint8Array; readTime?: Timestamp$1; } interface TransactionOptions { readOnly?: ReadOnly; readWrite?: ReadWrite; } interface UnaryFilter { op?: UnaryFilterOp; field?: FieldReference; } interface Value { nullValue?: ValueNullValue; booleanValue?: boolean; integerValue?: string | number; doubleValue?: string | number; timestampValue?: Timestamp$1; stringValue?: string; bytesValue?: string | Uint8Array; referenceValue?: string; geoPointValue?: LatLng; arrayValue?: ArrayValue; mapValue?: MapValue; fieldReferenceValue?: string; functionValue?: Function; pipelineValue?: Pipeline; } interface Write { update?: Document; delete?: string; verify?: string; transform?: DocumentTransform; updateMask?: DocumentMask; updateTransforms?: FieldTransform[]; currentDocument?: Precondition; } interface WriteRequest { streamId?: string; writes?: Write[]; streamToken?: string | Uint8Array; labels?: ApiClientObjectMap<string>; } interface WriteResponse { streamId?: string; streamToken?: string | Uint8Array; writeResults?: WriteResult[]; commitTime?: Timestamp$1; } interface WriteResult { updateTime?: Timestamp$1; transformResults?: Value[]; } } declare type MapValue = firestoreV1ApiClientInterfaces.MapValue; declare type Pipeline$2 = firestoreV1ApiClientInterfaces.Pipeline; declare type Stage$1 = firestoreV1ApiClientInterfaces.Stage; declare type StructuredQuery = firestoreV1ApiClientInterfaces.StructuredQuery; declare type Value = firestoreV1ApiClientInterfaces.Value; /** * Path represents an ordered sequence of string segments. */ declare abstract class BasePath<B extends BasePath<B>> { private segments; private offset; private len; constructor(segments: string[], offset?: number, length?: number); /** * Abstract constructor method to construct an instance of B with the given * parameters. */ protected abstract construct(segments: string[], offset?: number, length?: number): B; /** * Returns a String representation. * * Implementing classes are required to provide deterministic implementations as * the String representation is used to obtain canonical Query IDs. */ abstract toString(): string; get length(): number; isEqual(other: B): boolean; child(nameOrPath: string | B): B; /** The index of one past the last segment of the path. */ private limit; popFirst(size?: number): B; popLast(): B; firstSegment(): string; lastSegment(): string; get(index: number): string; isEmpty(): boolean; isPrefixOf(other: this): boolean; isImmediateParentOf(potentialChild: this): boolean; forEach(fn: (segment: string) => void): void; toArray(): string[]; /** * Compare 2 paths segment by segment, prioritizing numeric IDs * (e.g., "__id123__") in numeric ascending order, followed by string * segments in lexicographical order. */ static comparator<T extends BasePath<T>>(p1: BasePath<T>, p2: BasePath<T>): number; private static compareSegments; private static isNumericId; private static extractNumericId; } /** * A slash-separated path for navigating resources (documents and collections) * within Firestore. * * @internal */ declare class ResourcePath extends BasePath<ResourcePath> { protected construct(segments: string[], offset?: number, length?: number): ResourcePath; canonicalString(): string; toString(): string; /** * Returns a string representation of this path * where each path segment has been encoded with * `encodeURIComponent`. */ toUriEncodedString(): string; /** * Creates a resource path from the given slash-delimited string. If multiple * arguments are provided, all components are combined. Leading and trailing * slashes from all components are ignored. */ static fromString(...pathComponents: string[]): ResourcePath; static emptyPath(): ResourcePath; } /** * A dot-separated path for navigating sub-objects within a document. * @internal */ declare class FieldPath$2 extends BasePath<FieldPath$2> { protected construct(segments: string[], offset?: number, length?: number): FieldPath$2; /** * Returns true if the string could be used as a segment in a field path * without escaping. */ private static isValidIdentifier; canonicalString(): string; toString(): string; /** * Returns true if this field references the key of a document. */ isKeyField(): boolean; /** * The field designating the key of a document. */ static keyField(): FieldPath$2; /** * Parses a field string from the given server-formatted string. * * - Splitting the empty string is not allowed (for now at least). * - Empty segments within the string (e.g. if there are two consecutive * separators) are not allowed. * * TODO(b/37244157): we should make this more strict. Right now, it allows * non-identifier path components, even if they aren't escaped. */ static fromServerFormat(path: string): FieldPath$2; static emptyPath(): FieldPath$2; } /** * @license * Copyright 2023 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. */ /** * Union type representing the aggregate type to be performed. */ type AggregateType = 'count' | 'avg' | 'sum'; /** * @license * Copyright 2025 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. */ /** * A list of data types Firestore objects may serialize in their toJSON implemenetations. * @private * @internal */ type JsonTypeDesc = 'object' | 'string' | 'number' | 'boolean' | 'null' | 'undefined'; /** * An association of JsonTypeDesc values to their native types. * @private * @internal */ type TSType<T extends JsonTypeDesc> = T extends 'object' ? object : T extends 'string' ? string : T extends 'number' ? number : T extends 'boolean' ? boolean : T extends 'null' ? null : T extends 'undefined' ? undefined : never; /** * The representation of a JSON object property name and its type value. * @private * @internal */ interface Property<T extends JsonTypeDesc> { value?: TSType<T>; typeString: JsonTypeDesc; } /** * @license * Copyright 2017 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. */ /** * A `Timestamp` represents a point in time independent of any time zone or * calendar, represented as seconds and fractions of seconds at nanosecond * resolution in UTC Epoch time. * * It is encoded using the Proleptic Gregorian Calendar which extends the * Gregorian calendar backwards to year one. It is encoded assuming all minutes * are 60 seconds long, i.e. leap seconds are "smeared" so that no leap second * table is needed for interpretation. Range is from 0001-01-01T00:00:00Z to * 9999-12-31T23:59:59.999999999Z. * * For examples and further specifications, refer to the * {@link https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto | Timestamp definition}. */ declare class Timestamp { /** * The number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. */ readonly seconds: number; /** * The fractions of a second at nanosecond resolution.* */ readonly nanoseconds: number; /** * Creates a new timestamp with the current date, with millisecond precision. * * @returns a new timestamp representing the current date. */ static now(): Timestamp; /** * Creates a new timestamp from the given date. * * @param date - The date to initialize the `Timestamp` from. * @returns A new `Timestamp` representing the same point in time as the given * date. */ static fromDate(date: Date): Timestamp; /** * Creates a new timestamp from the given number of milliseconds. * * @param milliseconds - Number of milliseconds since Unix epoch * 1970-01-01T00:00:00Z. * @returns A new `Timestamp` representing the same point in time as the given * number of milliseconds. */ static fromMillis(milliseconds: number): Timestamp; /** * Creates a new timestamp. * * @param seconds - The number of seconds of UTC time since Unix epoch * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to * 9999-12-31T23:59:59Z inclusive. * @param nanoseconds - The non-negative fractions of a second at nanosecond * resolution. Negative second values with fractions must still have * non-negative nanoseconds values that count forward in time. Must be * from 0 to 999,999,999 inclusive. */ constructor( /** * The number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. */ seconds: number, /** * The fractions of a second at nanosecond resolution.* */ nanoseconds: number); /** * Converts a `Timestamp` to a JavaScript `Date` object. This conversion * causes a loss of precision since `Date` objects only support millisecond * precision. * * @returns JavaScript `Date` object representing the same point in time as * this `Timestamp`, with millisecond precision. */ toDate(): Date; /** * Converts a `Timestamp` to a numeric timestamp (in milliseconds since * epoch). This operation causes a loss of precision. * * @returns The point in time corresponding to this timestamp, represented as * the number of milliseconds since Unix epoch 1970-01-01T00:00:00Z. */ toMillis(): number; _compareTo(other: Timestamp): number; /** * Returns true if this `Timestamp` is equal to the provided one. * * @param other - The `Timestamp` to compare against. * @returns true if this `Timestamp` is equal to the provided one. */ isEqual(other: Timestamp): boolean; /** Returns a textual representation of this `Timestamp`. */ toString(): string; static _jsonSchemaVersion: string; static _jsonSchema: { type: Property<"string">; seconds: Property<"number">; nanoseconds: Property<"number">; }; /** * Returns a JSON-serializable representation of this `Timestamp`. */ toJSON(): { seconds: number; nanoseconds: number; type: string; }; /** * Builds a `Timestamp` instance from a JSON object created by {@link Timestamp.toJSON}. */ static fromJSON(json: object): Timestamp; /** * Converts this object to a primitive string, which allows `Timestamp` objects * to be compared using the `>`, `<=`, `>=` and `>` operators. */ valueOf(): string; } /** * @license * Copyright 2017 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. */ /** * A version of a document in Firestore. This corresponds to the version * timestamp, such as update_time or read_time. */ declare class SnapshotVersion { private timestamp; static fromTimestamp(value: Timestamp): SnapshotVersion; static min(): SnapshotVersion; static max(): SnapshotVersion; private constructor(); compareTo(other: SnapshotVersion): number; isEqual(other: SnapshotVersion): boolean; /** Returns a number representation of the version for use in spec tests. */ toMicroseconds(): number; toString(): string; toTimestamp(): Timestamp; } /** * @license * Copyright 2017 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. */ /** * @internal */ declare class DocumentKey { readonly path: ResourcePath; constructor(path: ResourcePath); static fromPath(path: string): DocumentKey; static fromName(name: string): DocumentKey; static empty(): DocumentKey; get collectionGroup(): string; /** Returns true if the document is in the specified collectionId. */ hasCollectionId(collectionId: string): boolean; /** Returns the collection group (i.e. the name of the parent collection) for this key. */ getCollectionGroup(): string; /** Returns the fully qualified path to the parent collection. */ getCollectionPath(): ResourcePath; isEqual(other: DocumentKey | null): boolean; toString(): string; static comparator(k1: DocumentKey, k2: DocumentKey): number; static isDocumentKey(path: ResourcePath): boolean; /** * Creates and returns a new document key with the given segments. * * @param segments - The segments of the path to the document * @returns A new instance of DocumentKey */ static fromSegments(segments: string[]): DocumentKey; } /** * @license * Copyright 2020 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. */ /** * Provides a set of fields that can be used to partially patch a document. * FieldMask is used in conjunction with ObjectValue. * Examples: * foo - Overwrites foo entirely with the provided value. If foo is not * present in the companion ObjectValue, the field is deleted. * foo.bar - Overwrites only the field bar of the object foo. * If foo is not an object, foo is replaced with an object * containing foo */ declare class FieldMask { readonly fields: FieldPath$2[]; constructor(fields: FieldPath$2[]); static empty(): FieldMask; /** * Returns a new FieldMask object that is the result of adding all the given * fields paths to this field mask. */ unionWith(extraFields: FieldPath$2[]): FieldMask; /** * Verifies that `fieldPath` is included by at least one field in this field * mask. * * This is an O(n) operation, where `n` is the size of the field mask. */ covers(fieldPath: FieldPath$2): boolean; isEqual(other: FieldMask): boolean; } /** * @license * Copyright 2017 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. */ /** * An ObjectValue represents a MapValue in the Firestore Proto and offers the * ability to add and remove fields (via the ObjectValueBuilder). */ declare class ObjectValue { readonly value: { mapValue: MapValue; }; constructor(value: { mapValue: MapValue; }); static empty(): ObjectValue; /** * Returns the value at the given path or null. * * @param path - the path to search * @returns The value at the path or null if the path is not set. */ field(path: FieldPath$2): Value | null; /** * Sets the field to the provided value. * * @param path - The field path to set. * @param value - The value to set. */ set(path: FieldPath$2, value: Value): void; /** * Sets the provided fields to the provided values. * * @param data - A map of fields to values (or null for deletes). */ setAll(data: Map<FieldPath$2, Value | null>): void; /** * Removes the field at the specified path. If there is no field at the * specified path, nothing is changed. * * @param path - The field path to remove. */ delete(path: FieldPath$2): void; isEqual(other: ObjectValue): boolean; /** * Returns the map that contains the leaf element of `path`. If the parent * entry does not yet exist, or if it is not a map, a new map will be created. */ private getFieldsMap; /** * Modifies `fieldsMap` by adding, replacing or deleting the specified * entries. */ private applyChanges; clone(): ObjectValue; } /** * @license * Copyright 2017 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. */ /** * Represents a document in Firestore with a key, version, data and whether the * data has local mutations applied to it. */ interface Document { /** The key for this document */ readonly key: DocumentKey; /** * The version of this document if it exists or a version at which this * document was guaranteed to not exist. */ readonly version: SnapshotVersion; /** * The timestamp at which this document was read from the remote server. Uses * `SnapshotVersion.min()` for documents created by the user. */ readonly readTime: SnapshotVersion; /** * The timestamp at which the document was created. This value increases * monotonically when a document is deleted then recreated. It can also be * compared to `createTime` of other documents and the `readTime` of a query. */ readonly createTime: SnapshotVersion; /** The underlying data of this document or an empty value if no data exists. */ readonly data: ObjectValue; /** Returns whether local mutations were applied via the mutation queue. */ readonly hasLocalMutations: boolean; /** Returns whether mutations were applied based on a write acknowledgment. */ readonly hasCommittedMutations: boolean; /** * Whether this document had a local mutation applied that has not yet been * acknowledged by Watch. */ readonly hasPendingWrites: boolean; /** * Returns whether this document is valid (i.e. it is an entry in the * RemoteDocumentCache, was created by a mutation or read from the backend). */ isValidDocument(): boolean; /** * Returns whether the document exists and its data is known at the current * version. */ isFoundDocument(): boolean; /** * Returns whether the document is known to not exist at the current version. */ isNoDocument(): boolean; /** * Returns whether the document exists and its data is unknown at the current * version. */ isUnknownDocument(): boolean; isEqual(other: Document | null | undefined): boolean; /** Creates a mutable copy of this document. */ mutableCopy(): MutableDocument; toString(): string; } /** * Represents a document in Firestore with a key, version, data and whether it * has local mutations applied to it. * * Documents can transition between states via `convertToFoundDocument()`, * `convertToNoDocument()` and `convertToUnknownDocument()`. If a document does * not transition to one of these states even after all mutations have been * applied, `isValidDocument()` returns false and the document should be removed * from all views. */ declare class MutableDocument implements Document { readonly key: DocumentKey; private documentType; version: SnapshotVersion; readTime: SnapshotVersion; createTime: SnapshotVersion; data: ObjectValue; private documentState; private constructor(); /** * Creates a document with no known version or data, but which can serve as * base document for mutations. */ static newInvalidDocument(documentKey: DocumentKey): MutableDocument; /** * Creates a new document that is known to exist with the given data at the * given version. */ static newFoundDocument(documentKey: DocumentKey, version: SnapshotVersion, createTime: SnapshotVersion, value: ObjectValue): MutableDocument; /** Creates a new document that is known to not exist at the given version. */ static newNoDocument(documentKey: DocumentKey, version: SnapshotVersion): MutableDocument; /** * Creates a new document that is known to exist at the given version but * whose data is not known (e.g. a document that was updated without a known * base document). */ static newUnknownDocument(documentKey: DocumentKey, version: SnapshotVersion): MutableDocument; /** * Changes the document type to indicate that it exists and that its version * and data are known. */ convertToFoundDocument(version: SnapshotVersion, value: ObjectValue): MutableDocument; /** * Changes the document type to indicate that it doesn't exist at the given * version. */ convertToNoDocument(version: SnapshotVersion): MutableDocument; /** * Changes the document type to indicate that it exists at a given version but * that its data is not known (e.g. a document that was updated without a known * base document). */ convertToUnknownDocument(version: SnapshotVersion): MutableDocument; setHasCommittedMutations(): MutableDocument; setHasLocalMutations(): MutableDocument; setReadTime(readTime: SnapshotVersion): MutableDocument; get hasLocalMutations(): boolean; get hasCommittedMutations(): boolean; get hasPendingWrites(): boolean; isValidDocument(): boolean; isFoundDocument(): boolean; isNoDocument(): boolean; isUnknownDocument(): boolean; isEqual(other: Document | null | undefined): boolean; mutableCopy(): MutableDocument; toString(): string; } /** * @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. */ declare const enum Operator { LESS_THAN = "<", LESS_THAN_OR_EQUAL = "<=", EQUAL = "==", NOT_EQUAL = "!=", GREATER_THAN = ">", GREATER_THAN_OR_EQUAL = ">=", ARRAY_CONTAINS = "array-contains", IN = "in", NOT_IN = "not-in", ARRAY_CONTAINS_ANY = "array-contains-any" } declare const enum CompositeOperator { OR = "or", AND = "and" } declare abstract class Filter { abstract matches(doc: Document): boolean; abstract getFlattenedFilters(): readonly FieldFilter[]; abstract getFilters(): Filter[]; } declare class FieldFilter extends Filter { readonly field: FieldPath$2; readonly op: Operator; readonly value: Value; protected constructor(field: FieldPath$2, op: Operator, value: Value); /** * Creates a filter based on the provided arguments. */ static create(field: FieldPath$2, op: Operator, value: Value): FieldFilter; private static createKeyFieldInFilter; matches(doc: Document): boolean; protected matchesComparison(comparison: number): boolean; isInequality(): boolean; getFlattenedFilters(): readonly FieldFilter[]; getFilters(): Filter[]; } /** * @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. */ /** * The direction of sorting in an order by. */ declare const enum Direction { ASCENDING = "asc", DESCENDING = "desc" } /** * An ordering on a field, in some Direction. Direction defaults to ASCENDING. */ declare class OrderBy { readonly field: FieldPath$2; readonly dir: Direction; constructor(field: FieldPath$2, dir?: Direction); } /** * @license * Copyright 2017 Google LLC * * Licensed under the Apache