GSI - Employe Self Service Mobile
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2331 lines
102 KiB

2 months ago
  1. /**
  2. * Cloud Firestore
  3. *
  4. * @packageDocumentation
  5. */
  6. import { FirebaseApp } from '@firebase/app';
  7. import { LogLevelString as LogLevel } from '@firebase/logger';
  8. import { EmulatorMockTokenOptions } from '@firebase/util';
  9. import { FirebaseError } from '@firebase/util';
  10. /**
  11. * Add a new document to specified `CollectionReference` with the given data,
  12. * assigning it a document ID automatically.
  13. *
  14. * @param reference - A reference to the collection to add this document to.
  15. * @param data - An Object containing the data for the new document.
  16. * @returns A `Promise` resolved with a `DocumentReference` pointing to the
  17. * newly created document after it has been written to the backend (Note that it
  18. * won't resolve while you're offline).
  19. */
  20. export declare function addDoc<T>(reference: CollectionReference<T>, data: WithFieldValue<T>): Promise<DocumentReference<T>>;
  21. /**
  22. * Returns a new map where every key is prefixed with the outer key appended
  23. * to a dot.
  24. */
  25. export declare type AddPrefixToKeys<Prefix extends string, T extends Record<string, unknown>> = {
  26. [K in keyof T & string as `${Prefix}.${K}`]+?: T[K];
  27. };
  28. /**
  29. * Represents an aggregation that can be performed by Firestore.
  30. */
  31. export declare class AggregateField<T> {
  32. /** A type string to uniquely identify instances of this class. */
  33. type: string;
  34. }
  35. /**
  36. * The union of all `AggregateField` types that are supported by Firestore.
  37. */
  38. export declare type AggregateFieldType = AggregateField<number>;
  39. /**
  40. * The results of executing an aggregation query.
  41. */
  42. export declare class AggregateQuerySnapshot<T extends AggregateSpec> {
  43. /** A type string to uniquely identify instances of this class. */
  44. readonly type = "AggregateQuerySnapshot";
  45. /**
  46. * The underlying query over which the aggregations recorded in this
  47. * `AggregateQuerySnapshot` were performed.
  48. */
  49. readonly query: Query<unknown>;
  50. private constructor();
  51. /**
  52. * Returns the results of the aggregations performed over the underlying
  53. * query.
  54. *
  55. * The keys of the returned object will be the same as those of the
  56. * `AggregateSpec` object specified to the aggregation method, and the values
  57. * will be the corresponding aggregation result.
  58. *
  59. * @returns The results of the aggregations performed over the underlying
  60. * query.
  61. */
  62. data(): AggregateSpecData<T>;
  63. }
  64. /**
  65. * Compares two `AggregateQuerySnapshot` instances for equality.
  66. *
  67. * Two `AggregateQuerySnapshot` instances are considered "equal" if they have
  68. * underlying queries that compare equal, and the same data.
  69. *
  70. * @param left - The first `AggregateQuerySnapshot` to compare.
  71. * @param right - The second `AggregateQuerySnapshot` to compare.
  72. *
  73. * @returns `true` if the objects are "equal", as defined above, or `false`
  74. * otherwise.
  75. */
  76. export declare function aggregateQuerySnapshotEqual<T extends AggregateSpec>(left: AggregateQuerySnapshot<T>, right: AggregateQuerySnapshot<T>): boolean;
  77. /**
  78. * A type whose property values are all `AggregateField` objects.
  79. */
  80. export declare interface AggregateSpec {
  81. [field: string]: AggregateFieldType;
  82. }
  83. /**
  84. * A type whose keys are taken from an `AggregateSpec`, and whose values are the
  85. * result of the aggregation performed by the corresponding `AggregateField`
  86. * from the input `AggregateSpec`.
  87. */
  88. export declare type AggregateSpecData<T extends AggregateSpec> = {
  89. [P in keyof T]: T[P] extends AggregateField<infer U> ? U : never;
  90. };
  91. /**
  92. * Returns a special value that can be used with {@link (setDoc:1)} or {@link
  93. * updateDoc:1} that tells the server to remove the given elements from any
  94. * array value that already exists on the server. All instances of each element
  95. * specified will be removed from the array. If the field being modified is not
  96. * already an array it will be overwritten with an empty array.
  97. *
  98. * @param elements - The elements to remove from the array.
  99. * @returns The `FieldValue` sentinel for use in a call to `setDoc()` or
  100. * `updateDoc()`
  101. */
  102. export declare function arrayRemove(...elements: unknown[]): FieldValue;
  103. /**
  104. * Returns a special value that can be used with {@link @firebase/firestore/lite#(setDoc:1)} or {@link
  105. * @firebase/firestore/lite#(updateDoc:1)} that tells the server to union the given elements with any array
  106. * value that already exists on the server. Each specified element that doesn't
  107. * already exist in the array will be added to the end. If the field being
  108. * modified is not already an array it will be overwritten with an array
  109. * containing exactly the specified elements.
  110. *
  111. * @param elements - The elements to union into the array.
  112. * @returns The `FieldValue` sentinel for use in a call to `setDoc()` or
  113. * `updateDoc()`.
  114. */
  115. export declare function arrayUnion(...elements: unknown[]): FieldValue;
  116. /**
  117. * An immutable object representing an array of bytes.
  118. */
  119. export declare class Bytes {
  120. private constructor();
  121. /**
  122. * Creates a new `Bytes` object from the given Base64 string, converting it to
  123. * bytes.
  124. *
  125. * @param base64 - The Base64 string used to create the `Bytes` object.
  126. */
  127. static fromBase64String(base64: string): Bytes;
  128. /**
  129. * Creates a new `Bytes` object from the given Uint8Array.
  130. *
  131. * @param array - The Uint8Array used to create the `Bytes` object.
  132. */
  133. static fromUint8Array(array: Uint8Array): Bytes;
  134. /**
  135. * Returns the underlying bytes as a Base64-encoded string.
  136. *
  137. * @returns The Base64-encoded string created from the `Bytes` object.
  138. */
  139. toBase64(): string;
  140. /**
  141. * Returns the underlying bytes in a new `Uint8Array`.
  142. *
  143. * @returns The Uint8Array created from the `Bytes` object.
  144. */
  145. toUint8Array(): Uint8Array;
  146. /**
  147. * Returns a string representation of the `Bytes` object.
  148. *
  149. * @returns A string representation of the `Bytes` object.
  150. */
  151. toString(): string;
  152. /**
  153. * Returns true if this `Bytes` object is equal to the provided one.
  154. *
  155. * @param other - The `Bytes` object to compare against.
  156. * @returns true if this `Bytes` object is equal to the provided one.
  157. */
  158. isEqual(other: Bytes): boolean;
  159. }
  160. /* Excluded from this release type: _ByteString */
  161. /**
  162. * Constant used to indicate the LRU garbage collection should be disabled.
  163. * Set this value as the `cacheSizeBytes` on the settings passed to the
  164. * {@link Firestore} instance.
  165. */
  166. export declare const CACHE_SIZE_UNLIMITED = -1;
  167. /**
  168. * Helper for calculating the nested fields for a given type T1. This is needed
  169. * to distribute union types such as `undefined | {...}` (happens for optional
  170. * props) or `{a: A} | {b: B}`.
  171. *
  172. * In this use case, `V` is used to distribute the union types of `T[K]` on
  173. * `Record`, since `T[K]` is evaluated as an expression and not distributed.
  174. *
  175. * See https://www.typescriptlang.org/docs/handbook/advanced-types.html#distributive-conditional-types
  176. */
  177. export declare type ChildUpdateFields<K extends string, V> = V extends Record<string, unknown> ? AddPrefixToKeys<K, UpdateData<V>> : never;
  178. /**
  179. * Clears the persistent storage. This includes pending writes and cached
  180. * documents.
  181. *
  182. * Must be called while the {@link Firestore} instance is not started (after the app is
  183. * terminated or when the app is first initialized). On startup, this function
  184. * must be called before other functions (other than {@link
  185. * initializeFirestore} or {@link (getFirestore:1)})). If the {@link Firestore}
  186. * instance is still running, the promise will be rejected with the error code
  187. * of `failed-precondition`.
  188. *
  189. * Note: `clearIndexedDbPersistence()` is primarily intended to help write
  190. * reliable tests that use Cloud Firestore. It uses an efficient mechanism for
  191. * dropping existing data but does not attempt to securely overwrite or
  192. * otherwise make cached data unrecoverable. For applications that are sensitive
  193. * to the disclosure of cached data in between user sessions, we strongly
  194. * recommend not enabling persistence at all.
  195. *
  196. * @param firestore - The {@link Firestore} instance to clear persistence for.
  197. * @returns A `Promise` that is resolved when the persistent storage is
  198. * cleared. Otherwise, the promise is rejected with an error.
  199. */
  200. export declare function clearIndexedDbPersistence(firestore: Firestore): Promise<void>;
  201. /**
  202. * Gets a `CollectionReference` instance that refers to the collection at
  203. * the specified absolute path.
  204. *
  205. * @param firestore - A reference to the root `Firestore` instance.
  206. * @param path - A slash-separated path to a collection.
  207. * @param pathSegments - Additional path segments to apply relative to the first
  208. * argument.
  209. * @throws If the final path has an even number of segments and does not point
  210. * to a collection.
  211. * @returns The `CollectionReference` instance.
  212. */
  213. export declare function collection(firestore: Firestore, path: string, ...pathSegments: string[]): CollectionReference<DocumentData>;
  214. /**
  215. * Gets a `CollectionReference` instance that refers to a subcollection of
  216. * `reference` at the the specified relative path.
  217. *
  218. * @param reference - A reference to a collection.
  219. * @param path - A slash-separated path to a collection.
  220. * @param pathSegments - Additional path segments to apply relative to the first
  221. * argument.
  222. * @throws If the final path has an even number of segments and does not point
  223. * to a collection.
  224. * @returns The `CollectionReference` instance.
  225. */
  226. export declare function collection(reference: CollectionReference<unknown>, path: string, ...pathSegments: string[]): CollectionReference<DocumentData>;
  227. /**
  228. * Gets a `CollectionReference` instance that refers to a subcollection of
  229. * `reference` at the the specified relative path.
  230. *
  231. * @param reference - A reference to a Firestore document.
  232. * @param path - A slash-separated path to a collection.
  233. * @param pathSegments - Additional path segments that will be applied relative
  234. * to the first argument.
  235. * @throws If the final path has an even number of segments and does not point
  236. * to a collection.
  237. * @returns The `CollectionReference` instance.
  238. */
  239. export declare function collection(reference: DocumentReference, path: string, ...pathSegments: string[]): CollectionReference<DocumentData>;
  240. /**
  241. * Creates and returns a new `Query` instance that includes all documents in the
  242. * database that are contained in a collection or subcollection with the
  243. * given `collectionId`.
  244. *
  245. * @param firestore - A reference to the root `Firestore` instance.
  246. * @param collectionId - Identifies the collections to query over. Every
  247. * collection or subcollection with this ID as the last segment of its path
  248. * will be included. Cannot contain a slash.
  249. * @returns The created `Query`.
  250. */
  251. export declare function collectionGroup(firestore: Firestore, collectionId: string): Query<DocumentData>;
  252. /**
  253. * A `CollectionReference` object can be used for adding documents, getting
  254. * document references, and querying for documents (using {@link query}).
  255. */
  256. export declare class CollectionReference<T = DocumentData> extends Query<T> {
  257. /** The type of this Firestore reference. */
  258. readonly type = "collection";
  259. private constructor();
  260. /** The collection's identifier. */
  261. get id(): string;
  262. /**
  263. * A string representing the path of the referenced collection (relative
  264. * to the root of the database).
  265. */
  266. get path(): string;
  267. /**
  268. * A reference to the containing `DocumentReference` if this is a
  269. * subcollection. If this isn't a subcollection, the reference is null.
  270. */
  271. get parent(): DocumentReference<DocumentData> | null;
  272. /**
  273. * Applies a custom data converter to this `CollectionReference`, allowing you
  274. * to use your own custom model objects with Firestore. When you call {@link
  275. * addDoc} with the returned `CollectionReference` instance, the provided
  276. * converter will convert between Firestore data and your custom type `U`.
  277. *
  278. * @param converter - Converts objects to and from Firestore.
  279. * @returns A `CollectionReference<U>` that uses the provided converter.
  280. */
  281. withConverter<U>(converter: FirestoreDataConverter<U>): CollectionReference<U>;
  282. /**
  283. * Removes the current converter.
  284. *
  285. * @param converter - `null` removes the current converter.
  286. * @returns A `CollectionReference<DocumentData>` that does not use a
  287. * converter.
  288. */
  289. withConverter(converter: null): CollectionReference<DocumentData>;
  290. }
  291. /**
  292. * Modify this instance to communicate with the Cloud Firestore emulator.
  293. *
  294. * Note: This must be called before this instance has been used to do any
  295. * operations.
  296. *
  297. * @param firestore - The `Firestore` instance to configure to connect to the
  298. * emulator.
  299. * @param host - the emulator host (ex: localhost).
  300. * @param port - the emulator port (ex: 9000).
  301. * @param options.mockUserToken - the mock auth token to use for unit testing
  302. * Security Rules.
  303. */
  304. export declare function connectFirestoreEmulator(firestore: Firestore, host: string, port: number, options?: {
  305. mockUserToken?: EmulatorMockTokenOptions | string;
  306. }): void;
  307. /**
  308. * Deletes the document referred to by the specified `DocumentReference`.
  309. *
  310. * @param reference - A reference to the document to delete.
  311. * @returns A Promise resolved once the document has been successfully
  312. * deleted from the backend (note that it won't resolve while you're offline).
  313. */
  314. export declare function deleteDoc(reference: DocumentReference<unknown>): Promise<void>;
  315. /**
  316. * Returns a sentinel for use with {@link @firebase/firestore/lite#(updateDoc:1)} or
  317. * {@link @firebase/firestore/lite#(setDoc:1)} with `{merge: true}` to mark a field for deletion.
  318. */
  319. export declare function deleteField(): FieldValue;
  320. /**
  321. * Disables network usage for this instance. It can be re-enabled via {@link
  322. * enableNetwork}. While the network is disabled, any snapshot listeners,
  323. * `getDoc()` or `getDocs()` calls will return results from cache, and any write
  324. * operations will be queued until the network is restored.
  325. *
  326. * @returns A `Promise` that is resolved once the network has been disabled.
  327. */
  328. export declare function disableNetwork(firestore: Firestore): Promise<void>;
  329. /**
  330. * Gets a `DocumentReference` instance that refers to the document at the
  331. * specified absolute path.
  332. *
  333. * @param firestore - A reference to the root `Firestore` instance.
  334. * @param path - A slash-separated path to a document.
  335. * @param pathSegments - Additional path segments that will be applied relative
  336. * to the first argument.
  337. * @throws If the final path has an odd number of segments and does not point to
  338. * a document.
  339. * @returns The `DocumentReference` instance.
  340. */
  341. export declare function doc(firestore: Firestore, path: string, ...pathSegments: string[]): DocumentReference<DocumentData>;
  342. /**
  343. * Gets a `DocumentReference` instance that refers to a document within
  344. * `reference` at the specified relative path. If no path is specified, an
  345. * automatically-generated unique ID will be used for the returned
  346. * `DocumentReference`.
  347. *
  348. * @param reference - A reference to a collection.
  349. * @param path - A slash-separated path to a document. Has to be omitted to use
  350. * auto-genrated IDs.
  351. * @param pathSegments - Additional path segments that will be applied relative
  352. * to the first argument.
  353. * @throws If the final path has an odd number of segments and does not point to
  354. * a document.
  355. * @returns The `DocumentReference` instance.
  356. */
  357. export declare function doc<T>(reference: CollectionReference<T>, path?: string, ...pathSegments: string[]): DocumentReference<T>;
  358. /**
  359. * Gets a `DocumentReference` instance that refers to a document within
  360. * `reference` at the specified relative path.
  361. *
  362. * @param reference - A reference to a Firestore document.
  363. * @param path - A slash-separated path to a document.
  364. * @param pathSegments - Additional path segments that will be applied relative
  365. * to the first argument.
  366. * @throws If the final path has an odd number of segments and does not point to
  367. * a document.
  368. * @returns The `DocumentReference` instance.
  369. */
  370. export declare function doc(reference: DocumentReference<unknown>, path: string, ...pathSegments: string[]): DocumentReference<DocumentData>;
  371. /**
  372. * A `DocumentChange` represents a change to the documents matching a query.
  373. * It contains the document affected and the type of change that occurred.
  374. */
  375. export declare interface DocumentChange<T = DocumentData> {
  376. /** The type of change ('added', 'modified', or 'removed'). */
  377. readonly type: DocumentChangeType;
  378. /** The document affected by this change. */
  379. readonly doc: QueryDocumentSnapshot<T>;
  380. /**
  381. * The index of the changed document in the result set immediately prior to
  382. * this `DocumentChange` (i.e. supposing that all prior `DocumentChange` objects
  383. * have been applied). Is `-1` for 'added' events.
  384. */
  385. readonly oldIndex: number;
  386. /**
  387. * The index of the changed document in the result set immediately after
  388. * this `DocumentChange` (i.e. supposing that all prior `DocumentChange`
  389. * objects and the current `DocumentChange` object have been applied).
  390. * Is -1 for 'removed' events.
  391. */
  392. readonly newIndex: number;
  393. }
  394. /**
  395. * The type of a `DocumentChange` may be 'added', 'removed', or 'modified'.
  396. */
  397. export declare type DocumentChangeType = 'added' | 'removed' | 'modified';
  398. /**
  399. * Document data (for use with {@link @firebase/firestore/lite#(setDoc:1)}) consists of fields mapped to
  400. * values.
  401. */
  402. export declare interface DocumentData {
  403. /** A mapping between a field and its value. */
  404. [field: string]: any;
  405. }
  406. /**
  407. * Returns a special sentinel `FieldPath` to refer to the ID of a document.
  408. * It can be used in queries to sort or filter by the document ID.
  409. */
  410. export declare function documentId(): FieldPath;
  411. /**
  412. * A `DocumentReference` refers to a document location in a Firestore database
  413. * and can be used to write, read, or listen to the location. The document at
  414. * the referenced location may or may not exist.
  415. */
  416. export declare class DocumentReference<T = DocumentData> {
  417. /**
  418. * If provided, the `FirestoreDataConverter` associated with this instance.
  419. */
  420. readonly converter: FirestoreDataConverter<T> | null;
  421. /** The type of this Firestore reference. */
  422. readonly type = "document";
  423. /**
  424. * The {@link Firestore} instance the document is in.
  425. * This is useful for performing transactions, for example.
  426. */
  427. readonly firestore: Firestore;
  428. private constructor();
  429. /**
  430. * The document's identifier within its collection.
  431. */
  432. get id(): string;
  433. /**
  434. * A string representing the path of the referenced document (relative
  435. * to the root of the database).
  436. */
  437. get path(): string;
  438. /**
  439. * The collection this `DocumentReference` belongs to.
  440. */
  441. get parent(): CollectionReference<T>;
  442. /**
  443. * Applies a custom data converter to this `DocumentReference`, allowing you
  444. * to use your own custom model objects with Firestore. When you call {@link
  445. * @firebase/firestore/lite#(setDoc:1)}, {@link @firebase/firestore/lite#getDoc}, etc. with the returned `DocumentReference`
  446. * instance, the provided converter will convert between Firestore data and
  447. * your custom type `U`.
  448. *
  449. * @param converter - Converts objects to and from Firestore.
  450. * @returns A `DocumentReference<U>` that uses the provided converter.
  451. */
  452. withConverter<U>(converter: FirestoreDataConverter<U>): DocumentReference<U>;
  453. /**
  454. * Removes the current converter.
  455. *
  456. * @param converter - `null` removes the current converter.
  457. * @returns A `DocumentReference<DocumentData>` that does not use a converter.
  458. */
  459. withConverter(converter: null): DocumentReference<DocumentData>;
  460. }
  461. /**
  462. * A `DocumentSnapshot` contains data read from a document in your Firestore
  463. * database. The data can be extracted with `.data()` or `.get(<field>)` to
  464. * get a specific field.
  465. *
  466. * For a `DocumentSnapshot` that points to a non-existing document, any data
  467. * access will return 'undefined'. You can use the `exists()` method to
  468. * explicitly verify a document's existence.
  469. */
  470. export declare class DocumentSnapshot<T = DocumentData> {
  471. /**
  472. * Metadata about the `DocumentSnapshot`, including information about its
  473. * source and local modifications.
  474. */
  475. readonly metadata: SnapshotMetadata;
  476. protected constructor();
  477. /**
  478. * Returns whether or not the data exists. True if the document exists.
  479. */
  480. exists(): this is QueryDocumentSnapshot<T>;
  481. /**
  482. * Retrieves all fields in the document as an `Object`. Returns `undefined` if
  483. * the document doesn't exist.
  484. *
  485. * By default, `serverTimestamp()` values that have not yet been
  486. * set to their final value will be returned as `null`. You can override
  487. * this by passing an options object.
  488. *
  489. * @param options - An options object to configure how data is retrieved from
  490. * the snapshot (for example the desired behavior for server timestamps that
  491. * have not yet been set to their final value).
  492. * @returns An `Object` containing all fields in the document or `undefined` if
  493. * the document doesn't exist.
  494. */
  495. data(options?: SnapshotOptions): T | undefined;
  496. /**
  497. * Retrieves the field specified by `fieldPath`. Returns `undefined` if the
  498. * document or field doesn't exist.
  499. *
  500. * By default, a `serverTimestamp()` that has not yet been set to
  501. * its final value will be returned as `null`. You can override this by
  502. * passing an options object.
  503. *
  504. * @param fieldPath - The path (for example 'foo' or 'foo.bar') to a specific
  505. * field.
  506. * @param options - An options object to configure how the field is retrieved
  507. * from the snapshot (for example the desired behavior for server timestamps
  508. * that have not yet been set to their final value).
  509. * @returns The data at the specified field location or undefined if no such
  510. * field exists in the document.
  511. */
  512. get(fieldPath: string | FieldPath, options?: SnapshotOptions): any;
  513. /**
  514. * Property of the `DocumentSnapshot` that provides the document's ID.
  515. */
  516. get id(): string;
  517. /**
  518. * The `DocumentReference` for the document included in the `DocumentSnapshot`.
  519. */
  520. get ref(): DocumentReference<T>;
  521. }
  522. /* Excluded from this release type: _EmptyAppCheckTokenProvider */
  523. /* Excluded from this release type: _EmptyAuthCredentialsProvider */
  524. export { EmulatorMockTokenOptions };
  525. /**
  526. * Attempts to enable persistent storage, if possible.
  527. *
  528. * Must be called before any other functions (other than
  529. * {@link initializeFirestore}, {@link (getFirestore:1)} or
  530. * {@link clearIndexedDbPersistence}.
  531. *
  532. * If this fails, `enableIndexedDbPersistence()` will reject the promise it
  533. * returns. Note that even after this failure, the {@link Firestore} instance will
  534. * remain usable, however offline persistence will be disabled.
  535. *
  536. * There are several reasons why this can fail, which can be identified by
  537. * the `code` on the error.
  538. *
  539. * * failed-precondition: The app is already open in another browser tab.
  540. * * unimplemented: The browser is incompatible with the offline
  541. * persistence implementation.
  542. *
  543. * @param firestore - The {@link Firestore} instance to enable persistence for.
  544. * @param persistenceSettings - Optional settings object to configure
  545. * persistence.
  546. * @returns A `Promise` that represents successfully enabling persistent storage.
  547. */
  548. export declare function enableIndexedDbPersistence(firestore: Firestore, persistenceSettings?: PersistenceSettings): Promise<void>;
  549. /**
  550. * Attempts to enable multi-tab persistent storage, if possible. If enabled
  551. * across all tabs, all operations share access to local persistence, including
  552. * shared execution of queries and latency-compensated local document updates
  553. * across all connected instances.
  554. *
  555. * If this fails, `enableMultiTabIndexedDbPersistence()` will reject the promise
  556. * it returns. Note that even after this failure, the {@link Firestore} instance will
  557. * remain usable, however offline persistence will be disabled.
  558. *
  559. * There are several reasons why this can fail, which can be identified by
  560. * the `code` on the error.
  561. *
  562. * * failed-precondition: The app is already open in another browser tab and
  563. * multi-tab is not enabled.
  564. * * unimplemented: The browser is incompatible with the offline
  565. * persistence implementation.
  566. *
  567. * @param firestore - The {@link Firestore} instance to enable persistence for.
  568. * @returns A `Promise` that represents successfully enabling persistent
  569. * storage.
  570. */
  571. export declare function enableMultiTabIndexedDbPersistence(firestore: Firestore): Promise<void>;
  572. /**
  573. * Re-enables use of the network for this {@link Firestore} instance after a prior
  574. * call to {@link disableNetwork}.
  575. *
  576. * @returns A `Promise` that is resolved once the network has been enabled.
  577. */
  578. export declare function enableNetwork(firestore: Firestore): Promise<void>;
  579. /**
  580. * Creates a {@link QueryEndAtConstraint} that modifies the result set to end at
  581. * the provided document (inclusive). The end position is relative to the order
  582. * of the query. The document must contain all of the fields provided in the
  583. * orderBy of the query.
  584. *
  585. * @param snapshot - The snapshot of the document to end at.
  586. * @returns A {@link QueryEndAtConstraint} to pass to `query()`
  587. */
  588. export declare function endAt(snapshot: DocumentSnapshot<unknown>): QueryEndAtConstraint;
  589. /**
  590. * Creates a {@link QueryEndAtConstraint} that modifies the result set to end at
  591. * the provided fields relative to the order of the query. The order of the field
  592. * values must match the order of the order by clauses of the query.
  593. *
  594. * @param fieldValues - The field values to end this query at, in order
  595. * of the query's order by.
  596. * @returns A {@link QueryEndAtConstraint} to pass to `query()`
  597. */
  598. export declare function endAt(...fieldValues: unknown[]): QueryEndAtConstraint;
  599. /**
  600. * Creates a {@link QueryEndAtConstraint} that modifies the result set to end
  601. * before the provided document (exclusive). The end position is relative to the
  602. * order of the query. The document must contain all of the fields provided in
  603. * the orderBy of the query.
  604. *
  605. * @param snapshot - The snapshot of the document to end before.
  606. * @returns A {@link QueryEndAtConstraint} to pass to `query()`
  607. */
  608. export declare function endBefore(snapshot: DocumentSnapshot<unknown>): QueryEndAtConstraint;
  609. /**
  610. * Creates a {@link QueryEndAtConstraint} that modifies the result set to end
  611. * before the provided fields relative to the order of the query. The order of
  612. * the field values must match the order of the order by clauses of the query.
  613. *
  614. * @param fieldValues - The field values to end this query before, in order
  615. * of the query's order by.
  616. * @returns A {@link QueryEndAtConstraint} to pass to `query()`
  617. */
  618. export declare function endBefore(...fieldValues: unknown[]): QueryEndAtConstraint;
  619. /**
  620. * A `FieldPath` refers to a field in a document. The path may consist of a
  621. * single field name (referring to a top-level field in the document), or a
  622. * list of field names (referring to a nested field in the document).
  623. *
  624. * Create a `FieldPath` by providing field names. If more than one field
  625. * name is provided, the path will point to a nested field in a document.
  626. */
  627. export declare class FieldPath {
  628. /**
  629. * Creates a `FieldPath` from the provided field names. If more than one field
  630. * name is provided, the path will point to a nested field in a document.
  631. *
  632. * @param fieldNames - A list of field names.
  633. */
  634. constructor(...fieldNames: string[]);
  635. /**
  636. * Returns true if this `FieldPath` is equal to the provided one.
  637. *
  638. * @param other - The `FieldPath` to compare against.
  639. * @returns true if this `FieldPath` is equal to the provided one.
  640. */
  641. isEqual(other: FieldPath): boolean;
  642. }
  643. /**
  644. * Sentinel values that can be used when writing document fields with `set()`
  645. * or `update()`.
  646. */
  647. export declare abstract class FieldValue {
  648. private constructor();
  649. /** Compares `FieldValue`s for equality. */
  650. abstract isEqual(other: FieldValue): boolean;
  651. }
  652. /* Excluded from this release type: _FirebaseService */
  653. /**
  654. * The Cloud Firestore service interface.
  655. *
  656. * Do not call this constructor directly. Instead, use {@link (getFirestore:1)}.
  657. */
  658. export declare class Firestore {
  659. /**
  660. * Whether it's a {@link Firestore} or Firestore Lite instance.
  661. */
  662. type: 'firestore-lite' | 'firestore';
  663. private constructor();
  664. /**
  665. * The {@link @firebase/app#FirebaseApp} associated with this `Firestore` service
  666. * instance.
  667. */
  668. get app(): FirebaseApp;
  669. /**
  670. * Returns a JSON-serializable representation of this `Firestore` instance.
  671. */
  672. toJSON(): object;
  673. }
  674. /**
  675. * Converter used by `withConverter()` to transform user objects of type `T`
  676. * into Firestore data.
  677. *
  678. * Using the converter allows you to specify generic type arguments when
  679. * storing and retrieving objects from Firestore.
  680. *
  681. * @example
  682. * ```typescript
  683. * class Post {
  684. * constructor(readonly title: string, readonly author: string) {}
  685. *
  686. * toString(): string {
  687. * return this.title + ', by ' + this.author;
  688. * }
  689. * }
  690. *
  691. * const postConverter = {
  692. * toFirestore(post: WithFieldValue<Post>): DocumentData {
  693. * return {title: post.title, author: post.author};
  694. * },
  695. * fromFirestore(
  696. * snapshot: QueryDocumentSnapshot,
  697. * options: SnapshotOptions
  698. * ): Post {
  699. * const data = snapshot.data(options)!;
  700. * return new Post(data.title, data.author);
  701. * }
  702. * };
  703. *
  704. * const postSnap = await firebase.firestore()
  705. * .collection('posts')
  706. * .withConverter(postConverter)
  707. * .doc().get();
  708. * const post = postSnap.data();
  709. * if (post !== undefined) {
  710. * post.title; // string
  711. * post.toString(); // Should be defined
  712. * post.someNonExistentProperty; // TS error
  713. * }
  714. * ```
  715. */
  716. export declare interface FirestoreDataConverter<T> {
  717. /**
  718. * Called by the Firestore SDK to convert a custom model object of type `T`
  719. * into a plain JavaScript object (suitable for writing directly to the
  720. * Firestore database). To use `set()` with `merge` and `mergeFields`,
  721. * `toFirestore()` must be defined with `PartialWithFieldValue<T>`.
  722. *
  723. * The `WithFieldValue<T>` type extends `T` to also allow FieldValues such as
  724. * {@link (deleteField:1)} to be used as property values.
  725. */
  726. toFirestore(modelObject: WithFieldValue<T>): DocumentData;
  727. /**
  728. * Called by the Firestore SDK to convert a custom model object of type `T`
  729. * into a plain JavaScript object (suitable for writing directly to the
  730. * Firestore database). Used with {@link (setDoc:1)}, {@link (WriteBatch.set:1)}
  731. * and {@link (Transaction.set:1)} with `merge:true` or `mergeFields`.
  732. *
  733. * The `PartialWithFieldValue<T>` type extends `Partial<T>` to allow
  734. * FieldValues such as {@link (arrayUnion:1)} to be used as property values.
  735. * It also supports nested `Partial` by allowing nested fields to be
  736. * omitted.
  737. */
  738. toFirestore(modelObject: PartialWithFieldValue<T>, options: SetOptions): DocumentData;
  739. /**
  740. * Called by the Firestore SDK to convert Firestore data into an object of
  741. * type T. You can access your data by calling: `snapshot.data(options)`.
  742. *
  743. * @param snapshot - A `QueryDocumentSnapshot` containing your data and metadata.
  744. * @param options - The `SnapshotOptions` from the initial call to `data()`.
  745. */
  746. fromFirestore(snapshot: QueryDocumentSnapshot<DocumentData>, options?: SnapshotOptions): T;
  747. }
  748. /** An error returned by a Firestore operation. */
  749. export declare class FirestoreError extends FirebaseError {
  750. /**
  751. * The backend error code associated with this error.
  752. */
  753. readonly code: FirestoreErrorCode;
  754. /**
  755. * A custom error description.
  756. */
  757. readonly message: string;
  758. /** The stack of the error. */
  759. readonly stack?: string;
  760. private constructor();
  761. }
  762. /**
  763. * The set of Firestore status codes. The codes are the same at the ones
  764. * exposed by gRPC here:
  765. * https://github.com/grpc/grpc/blob/master/doc/statuscodes.md
  766. *
  767. * Possible values:
  768. * - 'cancelled': The operation was cancelled (typically by the caller).
  769. * - 'unknown': Unknown error or an error from a different error domain.
  770. * - 'invalid-argument': Client specified an invalid argument. Note that this
  771. * differs from 'failed-precondition'. 'invalid-argument' indicates
  772. * arguments that are problematic regardless of the state of the system
  773. * (e.g. an invalid field name).
  774. * - 'deadline-exceeded': Deadline expired before operation could complete.
  775. * For operations that change the state of the system, this error may be
  776. * returned even if the operation has completed successfully. For example,
  777. * a successful response from a server could have been delayed long enough
  778. * for the deadline to expire.
  779. * - 'not-found': Some requested document was not found.
  780. * - 'already-exists': Some document that we attempted to create already
  781. * exists.
  782. * - 'permission-denied': The caller does not have permission to execute the
  783. * specified operation.
  784. * - 'resource-exhausted': Some resource has been exhausted, perhaps a
  785. * per-user quota, or perhaps the entire file system is out of space.
  786. * - 'failed-precondition': Operation was rejected because the system is not
  787. * in a state required for the operation's execution.
  788. * - 'aborted': The operation was aborted, typically due to a concurrency
  789. * issue like transaction aborts, etc.
  790. * - 'out-of-range': Operation was attempted past the valid range.
  791. * - 'unimplemented': Operation is not implemented or not supported/enabled.
  792. * - 'internal': Internal errors. Means some invariants expected by
  793. * underlying system has been broken. If you see one of these errors,
  794. * something is very broken.
  795. * - 'unavailable': The service is currently unavailable. This is most likely
  796. * a transient condition and may be corrected by retrying with a backoff.
  797. * - 'data-loss': Unrecoverable data loss or corruption.
  798. * - 'unauthenticated': The request does not have valid authentication
  799. * credentials for the operation.
  800. */
  801. export declare type FirestoreErrorCode = 'cancelled' | 'unknown' | 'invalid-argument' | 'deadline-exceeded' | 'not-found' | 'already-exists' | 'permission-denied' | 'resource-exhausted' | 'failed-precondition' | 'aborted' | 'out-of-range' | 'unimplemented' | 'internal' | 'unavailable' | 'data-loss' | 'unauthenticated';
  802. /**
  803. * Specifies custom configurations for your Cloud Firestore instance.
  804. * You must set these before invoking any other methods.
  805. */
  806. export declare interface FirestoreSettings {
  807. /**
  808. * An approximate cache size threshold for the on-disk data. If the cache
  809. * grows beyond this size, Firestore will start removing data that hasn't been
  810. * recently used. The size is not a guarantee that the cache will stay below
  811. * that size, only that if the cache exceeds the given size, cleanup will be
  812. * attempted.
  813. *
  814. * The default value is 40 MB. The threshold must be set to at least 1 MB, and
  815. * can be set to `CACHE_SIZE_UNLIMITED` to disable garbage collection.
  816. */
  817. cacheSizeBytes?: number;
  818. /**
  819. * Forces the SDKs underlying network transport (WebChannel) to use
  820. * long-polling. Each response from the backend will be closed immediately
  821. * after the backend sends data (by default responses are kept open in
  822. * case the backend has more data to send). This avoids incompatibility
  823. * issues with certain proxies, antivirus software, etc. that incorrectly
  824. * buffer traffic indefinitely. Use of this option will cause some
  825. * performance degradation though.
  826. *
  827. * This setting cannot be used with `experimentalAutoDetectLongPolling` and
  828. * may be removed in a future release. If you find yourself using it to
  829. * work around a specific network reliability issue, please tell us about
  830. * it in https://github.com/firebase/firebase-js-sdk/issues/1674.
  831. */
  832. experimentalForceLongPolling?: boolean;
  833. /**
  834. * Configures the SDK's underlying transport (WebChannel) to automatically
  835. * detect if long-polling should be used. This is very similar to
  836. * `experimentalForceLongPolling`, but only uses long-polling if required.
  837. *
  838. * This setting will likely be enabled by default in future releases and
  839. * cannot be combined with `experimentalForceLongPolling`.
  840. */
  841. experimentalAutoDetectLongPolling?: boolean;
  842. /**
  843. * The hostname to connect to.
  844. */
  845. host?: string;
  846. /**
  847. * Whether to use SSL when connecting.
  848. */
  849. ssl?: boolean;
  850. /**
  851. * Whether to skip nested properties that are set to `undefined` during
  852. * object serialization. If set to `true`, these properties are skipped
  853. * and not written to Firestore. If set to `false` or omitted, the SDK
  854. * throws an exception when it encounters properties of type `undefined`.
  855. */
  856. ignoreUndefinedProperties?: boolean;
  857. }
  858. /**
  859. * @license
  860. * Copyright 2017 Google LLC
  861. *
  862. * Licensed under the Apache License, Version 2.0 (the "License");
  863. * you may not use this file except in compliance with the License.
  864. * You may obtain a copy of the License at
  865. *
  866. * http://www.apache.org/licenses/LICENSE-2.0
  867. *
  868. * Unless required by applicable law or agreed to in writing, software
  869. * distributed under the License is distributed on an "AS IS" BASIS,
  870. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  871. * See the License for the specific language governing permissions and
  872. * limitations under the License.
  873. */
  874. /**
  875. * An immutable object representing a geographic location in Firestore. The
  876. * location is represented as latitude/longitude pair.
  877. *
  878. * Latitude values are in the range of [-90, 90].
  879. * Longitude values are in the range of [-180, 180].
  880. */
  881. export declare class GeoPoint {
  882. /**
  883. * Creates a new immutable `GeoPoint` object with the provided latitude and
  884. * longitude values.
  885. * @param latitude - The latitude as number between -90 and 90.
  886. * @param longitude - The longitude as number between -180 and 180.
  887. */
  888. constructor(latitude: number, longitude: number);
  889. /**
  890. * The latitude of this `GeoPoint` instance.
  891. */
  892. get latitude(): number;
  893. /**
  894. * The longitude of this `GeoPoint` instance.
  895. */
  896. get longitude(): number;
  897. /**
  898. * Returns true if this `GeoPoint` is equal to the provided one.
  899. *
  900. * @param other - The `GeoPoint` to compare against.
  901. * @returns true if this `GeoPoint` is equal to the provided one.
  902. */
  903. isEqual(other: GeoPoint): boolean;
  904. /** Returns a JSON-serializable representation of this GeoPoint. */
  905. toJSON(): {
  906. latitude: number;
  907. longitude: number;
  908. };
  909. }
  910. /**
  911. * Calculates the number of documents in the result set of the given query,
  912. * without actually downloading the documents.
  913. *
  914. * Using this function to count the documents is efficient because only the
  915. * final count, not the documents' data, is downloaded. This function can even
  916. * count the documents if the result set would be prohibitively large to
  917. * download entirely (e.g. thousands of documents).
  918. *
  919. * The result received from the server is presented, unaltered, without
  920. * considering any local state. That is, documents in the local cache are not
  921. * taken into consideration, neither are local modifications not yet
  922. * synchronized with the server. Previously-downloaded results, if any, are not
  923. * used: every request using this source necessarily involves a round trip to
  924. * the server.
  925. *
  926. * @param query - The query whose result set size to calculate.
  927. * @returns A Promise that will be resolved with the count; the count can be
  928. * retrieved from `snapshot.data().count`, where `snapshot` is the
  929. * `AggregateQuerySnapshot` to which the returned Promise resolves.
  930. */
  931. export declare function getCountFromServer(query: Query<unknown>): Promise<AggregateQuerySnapshot<{
  932. count: AggregateField<number>;
  933. }>>;
  934. /**
  935. * Reads the document referred to by this `DocumentReference`.
  936. *
  937. * Note: `getDoc()` attempts to provide up-to-date data when possible by waiting
  938. * for data from the server, but it may return cached data or fail if you are
  939. * offline and the server cannot be reached. To specify this behavior, invoke
  940. * {@link getDocFromCache} or {@link getDocFromServer}.
  941. *
  942. * @param reference - The reference of the document to fetch.
  943. * @returns A Promise resolved with a `DocumentSnapshot` containing the
  944. * current document contents.
  945. */
  946. export declare function getDoc<T>(reference: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
  947. /**
  948. * Reads the document referred to by this `DocumentReference` from cache.
  949. * Returns an error if the document is not currently cached.
  950. *
  951. * @returns A `Promise` resolved with a `DocumentSnapshot` containing the
  952. * current document contents.
  953. */
  954. export declare function getDocFromCache<T>(reference: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
  955. /**
  956. * Reads the document referred to by this `DocumentReference` from the server.
  957. * Returns an error if the network is not available.
  958. *
  959. * @returns A `Promise` resolved with a `DocumentSnapshot` containing the
  960. * current document contents.
  961. */
  962. export declare function getDocFromServer<T>(reference: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
  963. /**
  964. * Executes the query and returns the results as a `QuerySnapshot`.
  965. *
  966. * Note: `getDocs()` attempts to provide up-to-date data when possible by
  967. * waiting for data from the server, but it may return cached data or fail if
  968. * you are offline and the server cannot be reached. To specify this behavior,
  969. * invoke {@link getDocsFromCache} or {@link getDocsFromServer}.
  970. *
  971. * @returns A `Promise` that will be resolved with the results of the query.
  972. */
  973. export declare function getDocs<T>(query: Query<T>): Promise<QuerySnapshot<T>>;
  974. /**
  975. * Executes the query and returns the results as a `QuerySnapshot` from cache.
  976. * Returns an empty result set if no documents matching the query are currently
  977. * cached.
  978. *
  979. * @returns A `Promise` that will be resolved with the results of the query.
  980. */
  981. export declare function getDocsFromCache<T>(query: Query<T>): Promise<QuerySnapshot<T>>;
  982. /**
  983. * Executes the query and returns the results as a `QuerySnapshot` from the
  984. * server. Returns an error if the network is not available.
  985. *
  986. * @returns A `Promise` that will be resolved with the results of the query.
  987. */
  988. export declare function getDocsFromServer<T>(query: Query<T>): Promise<QuerySnapshot<T>>;
  989. /**
  990. * Returns the existing default {@link Firestore} instance that is associated with the
  991. * provided {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new
  992. * instance with default settings.
  993. *
  994. * @param app - The {@link @firebase/app#FirebaseApp} instance that the returned {@link Firestore}
  995. * instance is associated with.
  996. * @returns The {@link Firestore} instance of the provided app.
  997. */
  998. export declare function getFirestore(app: FirebaseApp): Firestore;
  999. /* Excluded declaration from this release type: getFirestore */
  1000. /**
  1001. * Returns the existing default {@link Firestore} instance that is associated with the
  1002. * default {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new
  1003. * instance with default settings.
  1004. *
  1005. * @returns The {@link Firestore} instance of the provided app.
  1006. */
  1007. export declare function getFirestore(): Firestore;
  1008. /* Excluded declaration from this release type: getFirestore */
  1009. /**
  1010. * Returns a special value that can be used with {@link @firebase/firestore/lite#(setDoc:1)} or {@link
  1011. * @firebase/firestore/lite#(updateDoc:1)} that tells the server to increment the field's current value by
  1012. * the given value.
  1013. *
  1014. * If either the operand or the current field value uses floating point
  1015. * precision, all arithmetic follows IEEE 754 semantics. If both values are
  1016. * integers, values outside of JavaScript's safe number range
  1017. * (`Number.MIN_SAFE_INTEGER` to `Number.MAX_SAFE_INTEGER`) are also subject to
  1018. * precision loss. Furthermore, once processed by the Firestore backend, all
  1019. * integer operations are capped between -2^63 and 2^63-1.
  1020. *
  1021. * If the current field value is not of type `number`, or if the field does not
  1022. * yet exist, the transformation sets the field to the given value.
  1023. *
  1024. * @param n - The value to increment by.
  1025. * @returns The `FieldValue` sentinel for use in a call to `setDoc()` or
  1026. * `updateDoc()`
  1027. */
  1028. export declare function increment(n: number): FieldValue;
  1029. /**
  1030. * The SDK definition of a Firestore index.
  1031. * @beta
  1032. */
  1033. export declare interface Index {
  1034. /** The ID of the collection to index. */
  1035. readonly collectionGroup: string;
  1036. /** A list of fields to index. */
  1037. readonly fields?: IndexField[];
  1038. [key: string]: unknown;
  1039. }
  1040. /**
  1041. * A list of Firestore indexes to speed up local query execution.
  1042. *
  1043. * See {@link https://firebase.google.com/docs/reference/firestore/indexes/#json_format | JSON Format}
  1044. * for a description of the format of the index definition.
  1045. * @beta
  1046. */
  1047. export declare interface IndexConfiguration {
  1048. /** A list of all Firestore indexes. */
  1049. readonly indexes?: Index[];
  1050. [key: string]: unknown;
  1051. }
  1052. /**
  1053. * A single field element in an index configuration.
  1054. * @beta
  1055. */
  1056. export declare interface IndexField {
  1057. /** The field path to index. */
  1058. readonly fieldPath: string;
  1059. /**
  1060. * What type of array index to create. Set to `CONTAINS` for `array-contains`
  1061. * and `array-contains-any` indexes.
  1062. *
  1063. * Only one of `arrayConfig` or `order` should be set;
  1064. */
  1065. readonly arrayConfig?: 'CONTAINS';
  1066. /**
  1067. * What type of array index to create. Set to `ASCENDING` or 'DESCENDING` for
  1068. * `==`, `!=`, `<=`, `<=`, `in` and `not-in` filters.
  1069. *
  1070. * Only one of `arrayConfig` or `order` should be set.
  1071. */
  1072. readonly order?: 'ASCENDING' | 'DESCENDING';
  1073. [key: string]: unknown;
  1074. }
  1075. /**
  1076. * Initializes a new instance of {@link Firestore} with the provided settings.
  1077. * Can only be called before any other function, including
  1078. * {@link (getFirestore:1)}. If the custom settings are empty, this function is
  1079. * equivalent to calling {@link (getFirestore:1)}.
  1080. *
  1081. * @param app - The {@link @firebase/app#FirebaseApp} with which the {@link Firestore} instance will
  1082. * be associated.
  1083. * @param settings - A settings object to configure the {@link Firestore} instance.
  1084. * @param databaseId - The name of database.
  1085. * @returns A newly initialized {@link Firestore} instance.
  1086. */
  1087. export declare function initializeFirestore(app: FirebaseApp, settings: FirestoreSettings, databaseId?: string): Firestore;
  1088. /* Excluded from this release type: _isBase64Available */
  1089. /**
  1090. * Creates a {@link QueryLimitConstraint} that only returns the first matching
  1091. * documents.
  1092. *
  1093. * @param limit - The maximum number of items to return.
  1094. * @returns The created {@link QueryLimitConstraint}.
  1095. */
  1096. export declare function limit(limit: number): QueryLimitConstraint;
  1097. /**
  1098. * Creates a {@link QueryLimitConstraint} that only returns the last matching
  1099. * documents.
  1100. *
  1101. * You must specify at least one `orderBy` clause for `limitToLast` queries,
  1102. * otherwise an exception will be thrown during execution.
  1103. *
  1104. * @param limit - The maximum number of items to return.
  1105. * @returns The created {@link QueryLimitConstraint}.
  1106. */
  1107. export declare function limitToLast(limit: number): QueryLimitConstraint;
  1108. /**
  1109. * Loads a Firestore bundle into the local cache.
  1110. *
  1111. * @param firestore - The {@link Firestore} instance to load bundles for.
  1112. * @param bundleData - An object representing the bundle to be loaded. Valid
  1113. * objects are `ArrayBuffer`, `ReadableStream<Uint8Array>` or `string`.
  1114. *
  1115. * @returns A `LoadBundleTask` object, which notifies callers with progress
  1116. * updates, and completion or error events. It can be used as a
  1117. * `Promise<LoadBundleTaskProgress>`.
  1118. */
  1119. export declare function loadBundle(firestore: Firestore, bundleData: ReadableStream<Uint8Array> | ArrayBuffer | string): LoadBundleTask;
  1120. /**
  1121. * Represents the task of loading a Firestore bundle. It provides progress of bundle
  1122. * loading, as well as task completion and error events.
  1123. *
  1124. * The API is compatible with `Promise<LoadBundleTaskProgress>`.
  1125. */
  1126. export declare class LoadBundleTask implements PromiseLike<LoadBundleTaskProgress> {
  1127. /**
  1128. * Registers functions to listen to bundle loading progress events.
  1129. * @param next - Called when there is a progress update from bundle loading. Typically `next` calls occur
  1130. * each time a Firestore document is loaded from the bundle.
  1131. * @param error - Called when an error occurs during bundle loading. The task aborts after reporting the
  1132. * error, and there should be no more updates after this.
  1133. * @param complete - Called when the loading task is complete.
  1134. */
  1135. onProgress(next?: (progress: LoadBundleTaskProgress) => unknown, error?: (err: Error) => unknown, complete?: () => void): void;
  1136. /**
  1137. * Implements the `Promise<LoadBundleTaskProgress>.catch` interface.
  1138. *
  1139. * @param onRejected - Called when an error occurs during bundle loading.
  1140. */
  1141. catch<R>(onRejected: (a: Error) => R | PromiseLike<R>): Promise<R | LoadBundleTaskProgress>;
  1142. /**
  1143. * Implements the `Promise<LoadBundleTaskProgress>.then` interface.
  1144. *
  1145. * @param onFulfilled - Called on the completion of the loading task with a final `LoadBundleTaskProgress` update.
  1146. * The update will always have its `taskState` set to `"Success"`.
  1147. * @param onRejected - Called when an error occurs during bundle loading.
  1148. */
  1149. then<T, R>(onFulfilled?: (a: LoadBundleTaskProgress) => T | PromiseLike<T>, onRejected?: (a: Error) => R | PromiseLike<R>): Promise<T | R>;
  1150. }
  1151. /**
  1152. * Represents a progress update or a final state from loading bundles.
  1153. */
  1154. export declare interface LoadBundleTaskProgress {
  1155. /** How many documents have been loaded. */
  1156. documentsLoaded: number;
  1157. /** How many documents are in the bundle being loaded. */
  1158. totalDocuments: number;
  1159. /** How many bytes have been loaded. */
  1160. bytesLoaded: number;
  1161. /** How many bytes are in the bundle being loaded. */
  1162. totalBytes: number;
  1163. /** Current task state. */
  1164. taskState: TaskState;
  1165. }
  1166. export { LogLevel };
  1167. /**
  1168. * Reads a Firestore {@link Query} from local cache, identified by the given
  1169. * name.
  1170. *
  1171. * The named queries are packaged into bundles on the server side (along
  1172. * with resulting documents), and loaded to local cache using `loadBundle`. Once
  1173. * in local cache, use this method to extract a {@link Query} by name.
  1174. *
  1175. * @param firestore - The {@link Firestore} instance to read the query from.
  1176. * @param name - The name of the query.
  1177. * @returns A `Promise` that is resolved with the Query or `null`.
  1178. */
  1179. export declare function namedQuery(firestore: Firestore, name: string): Promise<Query | null>;
  1180. /**
  1181. * For each field (e.g. 'bar'), find all nested keys (e.g. {'bar.baz': T1,
  1182. * 'bar.qux': T2}). Intersect them together to make a single map containing
  1183. * all possible keys that are all marked as optional
  1184. */
  1185. export declare type NestedUpdateFields<T extends Record<string, unknown>> = UnionToIntersection<{
  1186. [K in keyof T & string]: ChildUpdateFields<K, T[K]>;
  1187. }[keyof T & string]>;
  1188. /**
  1189. * Attaches a listener for `DocumentSnapshot` events. You may either pass
  1190. * individual `onNext` and `onError` callbacks or pass a single observer
  1191. * object with `next` and `error` callbacks.
  1192. *
  1193. * NOTE: Although an `onCompletion` callback can be provided, it will
  1194. * never be called because the snapshot stream is never-ending.
  1195. *
  1196. * @param reference - A reference to the document to listen to.
  1197. * @param observer - A single object containing `next` and `error` callbacks.
  1198. * @returns An unsubscribe function that can be called to cancel
  1199. * the snapshot listener.
  1200. */
  1201. export declare function onSnapshot<T>(reference: DocumentReference<T>, observer: {
  1202. next?: (snapshot: DocumentSnapshot<T>) => void;
  1203. error?: (error: FirestoreError) => void;
  1204. complete?: () => void;
  1205. }): Unsubscribe;
  1206. /**
  1207. * Attaches a listener for `DocumentSnapshot` events. You may either pass
  1208. * individual `onNext` and `onError` callbacks or pass a single observer
  1209. * object with `next` and `error` callbacks.
  1210. *
  1211. * NOTE: Although an `onCompletion` callback can be provided, it will
  1212. * never be called because the snapshot stream is never-ending.
  1213. *
  1214. * @param reference - A reference to the document to listen to.
  1215. * @param options - Options controlling the listen behavior.
  1216. * @param observer - A single object containing `next` and `error` callbacks.
  1217. * @returns An unsubscribe function that can be called to cancel
  1218. * the snapshot listener.
  1219. */
  1220. export declare function onSnapshot<T>(reference: DocumentReference<T>, options: SnapshotListenOptions, observer: {
  1221. next?: (snapshot: DocumentSnapshot<T>) => void;
  1222. error?: (error: FirestoreError) => void;
  1223. complete?: () => void;
  1224. }): Unsubscribe;
  1225. /**
  1226. * Attaches a listener for `DocumentSnapshot` events. You may either pass
  1227. * individual `onNext` and `onError` callbacks or pass a single observer
  1228. * object with `next` and `error` callbacks.
  1229. *
  1230. * NOTE: Although an `onCompletion` callback can be provided, it will
  1231. * never be called because the snapshot stream is never-ending.
  1232. *
  1233. * @param reference - A reference to the document to listen to.
  1234. * @param onNext - A callback to be called every time a new `DocumentSnapshot`
  1235. * is available.
  1236. * @param onError - A callback to be called if the listen fails or is
  1237. * cancelled. No further callbacks will occur.
  1238. * @param onCompletion - Can be provided, but will not be called since streams are
  1239. * never ending.
  1240. * @returns An unsubscribe function that can be called to cancel
  1241. * the snapshot listener.
  1242. */
  1243. export declare function onSnapshot<T>(reference: DocumentReference<T>, onNext: (snapshot: DocumentSnapshot<T>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe;
  1244. /**
  1245. * Attaches a listener for `DocumentSnapshot` events. You may either pass
  1246. * individual `onNext` and `onError` callbacks or pass a single observer
  1247. * object with `next` and `error` callbacks.
  1248. *
  1249. * NOTE: Although an `onCompletion` callback can be provided, it will
  1250. * never be called because the snapshot stream is never-ending.
  1251. *
  1252. * @param reference - A reference to the document to listen to.
  1253. * @param options - Options controlling the listen behavior.
  1254. * @param onNext - A callback to be called every time a new `DocumentSnapshot`
  1255. * is available.
  1256. * @param onError - A callback to be called if the listen fails or is
  1257. * cancelled. No further callbacks will occur.
  1258. * @param onCompletion - Can be provided, but will not be called since streams are
  1259. * never ending.
  1260. * @returns An unsubscribe function that can be called to cancel
  1261. * the snapshot listener.
  1262. */
  1263. export declare function onSnapshot<T>(reference: DocumentReference<T>, options: SnapshotListenOptions, onNext: (snapshot: DocumentSnapshot<T>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe;
  1264. /**
  1265. * Attaches a listener for `QuerySnapshot` events. You may either pass
  1266. * individual `onNext` and `onError` callbacks or pass a single observer
  1267. * object with `next` and `error` callbacks. The listener can be cancelled by
  1268. * calling the function that is returned when `onSnapshot` is called.
  1269. *
  1270. * NOTE: Although an `onCompletion` callback can be provided, it will
  1271. * never be called because the snapshot stream is never-ending.
  1272. *
  1273. * @param query - The query to listen to.
  1274. * @param observer - A single object containing `next` and `error` callbacks.
  1275. * @returns An unsubscribe function that can be called to cancel
  1276. * the snapshot listener.
  1277. */
  1278. export declare function onSnapshot<T>(query: Query<T>, observer: {
  1279. next?: (snapshot: QuerySnapshot<T>) => void;
  1280. error?: (error: FirestoreError) => void;
  1281. complete?: () => void;
  1282. }): Unsubscribe;
  1283. /**
  1284. * Attaches a listener for `QuerySnapshot` events. You may either pass
  1285. * individual `onNext` and `onError` callbacks or pass a single observer
  1286. * object with `next` and `error` callbacks. The listener can be cancelled by
  1287. * calling the function that is returned when `onSnapshot` is called.
  1288. *
  1289. * NOTE: Although an `onCompletion` callback can be provided, it will
  1290. * never be called because the snapshot stream is never-ending.
  1291. *
  1292. * @param query - The query to listen to.
  1293. * @param options - Options controlling the listen behavior.
  1294. * @param observer - A single object containing `next` and `error` callbacks.
  1295. * @returns An unsubscribe function that can be called to cancel
  1296. * the snapshot listener.
  1297. */
  1298. export declare function onSnapshot<T>(query: Query<T>, options: SnapshotListenOptions, observer: {
  1299. next?: (snapshot: QuerySnapshot<T>) => void;
  1300. error?: (error: FirestoreError) => void;
  1301. complete?: () => void;
  1302. }): Unsubscribe;
  1303. /**
  1304. * Attaches a listener for `QuerySnapshot` events. You may either pass
  1305. * individual `onNext` and `onError` callbacks or pass a single observer
  1306. * object with `next` and `error` callbacks. The listener can be cancelled by
  1307. * calling the function that is returned when `onSnapshot` is called.
  1308. *
  1309. * NOTE: Although an `onCompletion` callback can be provided, it will
  1310. * never be called because the snapshot stream is never-ending.
  1311. *
  1312. * @param query - The query to listen to.
  1313. * @param onNext - A callback to be called every time a new `QuerySnapshot`
  1314. * is available.
  1315. * @param onCompletion - Can be provided, but will not be called since streams are
  1316. * never ending.
  1317. * @param onError - A callback to be called if the listen fails or is
  1318. * cancelled. No further callbacks will occur.
  1319. * @returns An unsubscribe function that can be called to cancel
  1320. * the snapshot listener.
  1321. */
  1322. export declare function onSnapshot<T>(query: Query<T>, onNext: (snapshot: QuerySnapshot<T>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe;
  1323. /**
  1324. * Attaches a listener for `QuerySnapshot` events. You may either pass
  1325. * individual `onNext` and `onError` callbacks or pass a single observer
  1326. * object with `next` and `error` callbacks. The listener can be cancelled by
  1327. * calling the function that is returned when `onSnapshot` is called.
  1328. *
  1329. * NOTE: Although an `onCompletion` callback can be provided, it will
  1330. * never be called because the snapshot stream is never-ending.
  1331. *
  1332. * @param query - The query to listen to.
  1333. * @param options - Options controlling the listen behavior.
  1334. * @param onNext - A callback to be called every time a new `QuerySnapshot`
  1335. * is available.
  1336. * @param onCompletion - Can be provided, but will not be called since streams are
  1337. * never ending.
  1338. * @param onError - A callback to be called if the listen fails or is
  1339. * cancelled. No further callbacks will occur.
  1340. * @returns An unsubscribe function that can be called to cancel
  1341. * the snapshot listener.
  1342. */
  1343. export declare function onSnapshot<T>(query: Query<T>, options: SnapshotListenOptions, onNext: (snapshot: QuerySnapshot<T>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe;
  1344. /**
  1345. * Attaches a listener for a snapshots-in-sync event. The snapshots-in-sync
  1346. * event indicates that all listeners affected by a given change have fired,
  1347. * even if a single server-generated change affects multiple listeners.
  1348. *
  1349. * NOTE: The snapshots-in-sync event only indicates that listeners are in sync
  1350. * with each other, but does not relate to whether those snapshots are in sync
  1351. * with the server. Use SnapshotMetadata in the individual listeners to
  1352. * determine if a snapshot is from the cache or the server.
  1353. *
  1354. * @param firestore - The instance of Firestore for synchronizing snapshots.
  1355. * @param observer - A single object containing `next` and `error` callbacks.
  1356. * @returns An unsubscribe function that can be called to cancel the snapshot
  1357. * listener.
  1358. */
  1359. export declare function onSnapshotsInSync(firestore: Firestore, observer: {
  1360. next?: (value: void) => void;
  1361. error?: (error: FirestoreError) => void;
  1362. complete?: () => void;
  1363. }): Unsubscribe;
  1364. /**
  1365. * Attaches a listener for a snapshots-in-sync event. The snapshots-in-sync
  1366. * event indicates that all listeners affected by a given change have fired,
  1367. * even if a single server-generated change affects multiple listeners.
  1368. *
  1369. * NOTE: The snapshots-in-sync event only indicates that listeners are in sync
  1370. * with each other, but does not relate to whether those snapshots are in sync
  1371. * with the server. Use `SnapshotMetadata` in the individual listeners to
  1372. * determine if a snapshot is from the cache or the server.
  1373. *
  1374. * @param firestore - The `Firestore` instance for synchronizing snapshots.
  1375. * @param onSync - A callback to be called every time all snapshot listeners are
  1376. * in sync with each other.
  1377. * @returns An unsubscribe function that can be called to cancel the snapshot
  1378. * listener.
  1379. */
  1380. export declare function onSnapshotsInSync(firestore: Firestore, onSync: () => void): Unsubscribe;
  1381. /**
  1382. * Creates a {@link QueryOrderByConstraint} that sorts the query result by the
  1383. * specified field, optionally in descending order instead of ascending.
  1384. *
  1385. * Note: Documents that do not contain the specified field will not be present
  1386. * in the query result.
  1387. *
  1388. * @param fieldPath - The field to sort by.
  1389. * @param directionStr - Optional direction to sort by ('asc' or 'desc'). If
  1390. * not specified, order will be ascending.
  1391. * @returns The created {@link QueryOrderByConstraint}.
  1392. */
  1393. export declare function orderBy(fieldPath: string | FieldPath, directionStr?: OrderByDirection): QueryOrderByConstraint;
  1394. /**
  1395. * The direction of a {@link orderBy} clause is specified as 'desc' or 'asc'
  1396. * (descending or ascending).
  1397. */
  1398. export declare type OrderByDirection = 'desc' | 'asc';
  1399. /**
  1400. * Similar to Typescript's `Partial<T>`, but allows nested fields to be
  1401. * omitted and FieldValues to be passed in as property values.
  1402. */
  1403. export declare type PartialWithFieldValue<T> = Partial<T> | (T extends Primitive ? T : T extends {} ? {
  1404. [K in keyof T]?: PartialWithFieldValue<T[K]> | FieldValue;
  1405. } : never);
  1406. /**
  1407. * Settings that can be passed to `enableIndexedDbPersistence()` to configure
  1408. * Firestore persistence.
  1409. */
  1410. export declare interface PersistenceSettings {
  1411. /**
  1412. * Whether to force enable persistence for the client. This cannot be used
  1413. * with multi-tab synchronization and is primarily intended for use with Web
  1414. * Workers. Setting this to `true` will enable persistence, but cause other
  1415. * tabs using persistence to fail.
  1416. */
  1417. forceOwnership?: boolean;
  1418. }
  1419. /**
  1420. * These types primarily exist to support the `UpdateData`,
  1421. * `WithFieldValue`, and `PartialWithFieldValue` types and are not consumed
  1422. * directly by the end developer.
  1423. */
  1424. /** Primitive types. */
  1425. export declare type Primitive = string | number | boolean | undefined | null;
  1426. /**
  1427. * A `Query` refers to a query which you can read or listen to. You can also
  1428. * construct refined `Query` objects by adding filters and ordering.
  1429. */
  1430. export declare class Query<T = DocumentData> {
  1431. /**
  1432. * If provided, the `FirestoreDataConverter` associated with this instance.
  1433. */
  1434. readonly converter: FirestoreDataConverter<T> | null;
  1435. /** The type of this Firestore reference. */
  1436. readonly type: 'query' | 'collection';
  1437. /**
  1438. * The `Firestore` instance for the Firestore database (useful for performing
  1439. * transactions, etc.).
  1440. */
  1441. readonly firestore: Firestore;
  1442. protected constructor();
  1443. /**
  1444. * Removes the current converter.
  1445. *
  1446. * @param converter - `null` removes the current converter.
  1447. * @returns A `Query<DocumentData>` that does not use a converter.
  1448. */
  1449. withConverter(converter: null): Query<DocumentData>;
  1450. /**
  1451. * Applies a custom data converter to this query, allowing you to use your own
  1452. * custom model objects with Firestore. When you call {@link getDocs} with
  1453. * the returned query, the provided converter will convert between Firestore
  1454. * data and your custom type `U`.
  1455. *
  1456. * @param converter - Converts objects to and from Firestore.
  1457. * @returns A `Query<U>` that uses the provided converter.
  1458. */
  1459. withConverter<U>(converter: FirestoreDataConverter<U>): Query<U>;
  1460. }
  1461. /* Excluded declaration from this release type: query */
  1462. /**
  1463. * Creates a new immutable instance of {@link Query} that is extended to also
  1464. * include additional query constraints.
  1465. *
  1466. * @param query - The {@link Query} instance to use as a base for the new
  1467. * constraints.
  1468. * @param queryConstraints - The list of {@link QueryConstraint}s to apply.
  1469. * @throws if any of the provided query constraints cannot be combined with the
  1470. * existing or new constraints.
  1471. */
  1472. export declare function query<T>(query: Query<T>, ...queryConstraints: QueryConstraint[]): Query<T>;
  1473. /* Excluded from this release type: QueryCompositeFilterConstraint */
  1474. /**
  1475. * A `QueryConstraint` is used to narrow the set of documents returned by a
  1476. * Firestore query. `QueryConstraint`s are created by invoking {@link where},
  1477. * {@link orderBy}, {@link startAt}, {@link startAfter}, {@link
  1478. * endBefore}, {@link endAt}, {@link limit}, {@link limitToLast} and
  1479. * can then be passed to {@link query} to create a new query instance that
  1480. * also contains this `QueryConstraint`.
  1481. */
  1482. export declare abstract class QueryConstraint {
  1483. /** The type of this query constraint */
  1484. abstract readonly type: QueryConstraintType;
  1485. }
  1486. /** Describes the different query constraints available in this SDK. */
  1487. export declare type QueryConstraintType = 'where' | 'orderBy' | 'limit' | 'limitToLast' | 'startAt' | 'startAfter' | 'endAt' | 'endBefore';
  1488. /**
  1489. * A `QueryDocumentSnapshot` contains data read from a document in your
  1490. * Firestore database as part of a query. The document is guaranteed to exist
  1491. * and its data can be extracted with `.data()` or `.get(<field>)` to get a
  1492. * specific field.
  1493. *
  1494. * A `QueryDocumentSnapshot` offers the same API surface as a
  1495. * `DocumentSnapshot`. Since query results contain only existing documents, the
  1496. * `exists` property will always be true and `data()` will never return
  1497. * 'undefined'.
  1498. */
  1499. export declare class QueryDocumentSnapshot<T = DocumentData> extends DocumentSnapshot<T> {
  1500. /**
  1501. * Retrieves all fields in the document as an `Object`.
  1502. *
  1503. * By default, `serverTimestamp()` values that have not yet been
  1504. * set to their final value will be returned as `null`. You can override
  1505. * this by passing an options object.
  1506. *
  1507. * @override
  1508. * @param options - An options object to configure how data is retrieved from
  1509. * the snapshot (for example the desired behavior for server timestamps that
  1510. * have not yet been set to their final value).
  1511. * @returns An `Object` containing all fields in the document.
  1512. */
  1513. data(options?: SnapshotOptions): T;
  1514. }
  1515. /**
  1516. * A `QueryEndAtConstraint` is used to exclude documents from the end of a
  1517. * result set returned by a Firestore query.
  1518. * `QueryEndAtConstraint`s are created by invoking {@link (endAt:1)} or
  1519. * {@link (endBefore:1)} and can then be passed to {@link query} to create a new
  1520. * query instance that also contains this `QueryEndAtConstraint`.
  1521. */
  1522. export declare class QueryEndAtConstraint extends QueryConstraint {
  1523. /** The type of this query constraint */
  1524. readonly type: 'endBefore' | 'endAt';
  1525. }
  1526. /**
  1527. * Returns true if the provided queries point to the same collection and apply
  1528. * the same constraints.
  1529. *
  1530. * @param left - A `Query` to compare.
  1531. * @param right - A `Query` to compare.
  1532. * @returns true if the references point to the same location in the same
  1533. * Firestore database.
  1534. */
  1535. export declare function queryEqual<T>(left: Query<T>, right: Query<T>): boolean;
  1536. /**
  1537. * A `QueryFieldFilterConstraint` is used to narrow the set of documents returned by
  1538. * a Firestore query by filtering on one or more document fields.
  1539. * `QueryFieldFilterConstraint`s are created by invoking {@link where} and can then
  1540. * be passed to {@link query} to create a new query instance that also contains
  1541. * this `QueryFieldFilterConstraint`.
  1542. */
  1543. export declare class QueryFieldFilterConstraint extends QueryConstraint {
  1544. /** The type of this query constraint */
  1545. readonly type = "where";
  1546. }
  1547. /* Excluded from this release type: QueryFilterConstraint */
  1548. /**
  1549. * A `QueryLimitConstraint` is used to limit the number of documents returned by
  1550. * a Firestore query.
  1551. * `QueryLimitConstraint`s are created by invoking {@link limit} or
  1552. * {@link limitToLast} and can then be passed to {@link query} to create a new
  1553. * query instance that also contains this `QueryLimitConstraint`.
  1554. */
  1555. export declare class QueryLimitConstraint extends QueryConstraint {
  1556. /** The type of this query constraint */
  1557. readonly type: 'limit' | 'limitToLast';
  1558. }
  1559. /**
  1560. * `QueryNonFilterConstraint` is a helper union type that represents
  1561. * QueryConstraints which are used to narrow or order the set of documents,
  1562. * but that do not explicitly filter on a document field.
  1563. * `QueryNonFilterConstraint`s are created by invoking {@link orderBy},
  1564. * {@link startAt}, {@link startAfter}, {@link endBefore}, {@link endAt},
  1565. * {@link limit} or {@link limitToLast} and can then be passed to {@link query}
  1566. * to create a new query instance that also contains the `QueryConstraint`.
  1567. */
  1568. export declare type QueryNonFilterConstraint = QueryOrderByConstraint | QueryLimitConstraint | QueryStartAtConstraint | QueryEndAtConstraint;
  1569. /**
  1570. * A `QueryOrderByConstraint` is used to sort the set of documents returned by a
  1571. * Firestore query. `QueryOrderByConstraint`s are created by invoking
  1572. * {@link orderBy} and can then be passed to {@link query} to create a new query
  1573. * instance that also contains this `QueryOrderByConstraint`.
  1574. *
  1575. * Note: Documents that do not contain the orderBy field will not be present in
  1576. * the query result.
  1577. */
  1578. export declare class QueryOrderByConstraint extends QueryConstraint {
  1579. /** The type of this query constraint */
  1580. readonly type = "orderBy";
  1581. }
  1582. /**
  1583. * A `QuerySnapshot` contains zero or more `DocumentSnapshot` objects
  1584. * representing the results of a query. The documents can be accessed as an
  1585. * array via the `docs` property or enumerated using the `forEach` method. The
  1586. * number of documents can be determined via the `empty` and `size`
  1587. * properties.
  1588. */
  1589. export declare class QuerySnapshot<T = DocumentData> {
  1590. /**
  1591. * Metadata about this snapshot, concerning its source and if it has local
  1592. * modifications.
  1593. */
  1594. readonly metadata: SnapshotMetadata;
  1595. /**
  1596. * The query on which you called `get` or `onSnapshot` in order to get this
  1597. * `QuerySnapshot`.
  1598. */
  1599. readonly query: Query<T>;
  1600. private constructor();
  1601. /** An array of all the documents in the `QuerySnapshot`. */
  1602. get docs(): Array<QueryDocumentSnapshot<T>>;
  1603. /** The number of documents in the `QuerySnapshot`. */
  1604. get size(): number;
  1605. /** True if there are no documents in the `QuerySnapshot`. */
  1606. get empty(): boolean;
  1607. /**
  1608. * Enumerates all of the documents in the `QuerySnapshot`.
  1609. *
  1610. * @param callback - A callback to be called with a `QueryDocumentSnapshot` for
  1611. * each document in the snapshot.
  1612. * @param thisArg - The `this` binding for the callback.
  1613. */
  1614. forEach(callback: (result: QueryDocumentSnapshot<T>) => void, thisArg?: unknown): void;
  1615. /**
  1616. * Returns an array of the documents changes since the last snapshot. If this
  1617. * is the first snapshot, all documents will be in the list as 'added'
  1618. * changes.
  1619. *
  1620. * @param options - `SnapshotListenOptions` that control whether metadata-only
  1621. * changes (i.e. only `DocumentSnapshot.metadata` changed) should trigger
  1622. * snapshot events.
  1623. */
  1624. docChanges(options?: SnapshotListenOptions): Array<DocumentChange<T>>;
  1625. }
  1626. /**
  1627. * A `QueryStartAtConstraint` is used to exclude documents from the start of a
  1628. * result set returned by a Firestore query.
  1629. * `QueryStartAtConstraint`s are created by invoking {@link (startAt:1)} or
  1630. * {@link (startAfter:1)} and can then be passed to {@link query} to create a
  1631. * new query instance that also contains this `QueryStartAtConstraint`.
  1632. */
  1633. export declare class QueryStartAtConstraint extends QueryConstraint {
  1634. /** The type of this query constraint */
  1635. readonly type: 'startAt' | 'startAfter';
  1636. }
  1637. /**
  1638. * Returns true if the provided references are equal.
  1639. *
  1640. * @param left - A reference to compare.
  1641. * @param right - A reference to compare.
  1642. * @returns true if the references point to the same location in the same
  1643. * Firestore database.
  1644. */
  1645. export declare function refEqual<T>(left: DocumentReference<T> | CollectionReference<T>, right: DocumentReference<T> | CollectionReference<T>): boolean;
  1646. /* Excluded from this release type: _ResourcePath */
  1647. /**
  1648. * Executes the given `updateFunction` and then attempts to commit the changes
  1649. * applied within the transaction. If any document read within the transaction
  1650. * has changed, Cloud Firestore retries the `updateFunction`. If it fails to
  1651. * commit after 5 attempts, the transaction fails.
  1652. *
  1653. * The maximum number of writes allowed in a single transaction is 500.
  1654. *
  1655. * @param firestore - A reference to the Firestore database to run this
  1656. * transaction against.
  1657. * @param updateFunction - The function to execute within the transaction
  1658. * context.
  1659. * @param options - An options object to configure maximum number of attempts to
  1660. * commit.
  1661. * @returns If the transaction completed successfully or was explicitly aborted
  1662. * (the `updateFunction` returned a failed promise), the promise returned by the
  1663. * `updateFunction `is returned here. Otherwise, if the transaction failed, a
  1664. * rejected promise with the corresponding failure error is returned.
  1665. */
  1666. export declare function runTransaction<T>(firestore: Firestore, updateFunction: (transaction: Transaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
  1667. /**
  1668. * Returns a sentinel used with {@link @firebase/firestore/lite#(setDoc:1)} or {@link @firebase/firestore/lite#(updateDoc:1)} to
  1669. * include a server-generated timestamp in the written data.
  1670. */
  1671. export declare function serverTimestamp(): FieldValue;
  1672. /**
  1673. * Writes to the document referred to by this `DocumentReference`. If the
  1674. * document does not yet exist, it will be created.
  1675. *
  1676. * @param reference - A reference to the document to write.
  1677. * @param data - A map of the fields and values for the document.
  1678. * @returns A `Promise` resolved once the data has been successfully written
  1679. * to the backend (note that it won't resolve while you're offline).
  1680. */
  1681. export declare function setDoc<T>(reference: DocumentReference<T>, data: WithFieldValue<T>): Promise<void>;
  1682. /**
  1683. * Writes to the document referred to by the specified `DocumentReference`. If
  1684. * the document does not yet exist, it will be created. If you provide `merge`
  1685. * or `mergeFields`, the provided data can be merged into an existing document.
  1686. *
  1687. * @param reference - A reference to the document to write.
  1688. * @param data - A map of the fields and values for the document.
  1689. * @param options - An object to configure the set behavior.
  1690. * @returns A Promise resolved once the data has been successfully written
  1691. * to the backend (note that it won't resolve while you're offline).
  1692. */
  1693. export declare function setDoc<T>(reference: DocumentReference<T>, data: PartialWithFieldValue<T>, options: SetOptions): Promise<void>;
  1694. /**
  1695. * Configures indexing for local query execution. Any previous index
  1696. * configuration is overridden. The `Promise` resolves once the index
  1697. * configuration has been persisted.
  1698. *
  1699. * The index entries themselves are created asynchronously. You can continue to
  1700. * use queries that require indexing even if the indices are not yet available.
  1701. * Query execution will automatically start using the index once the index
  1702. * entries have been written.
  1703. *
  1704. * Indexes are only supported with IndexedDb persistence. Invoke either
  1705. * `enableIndexedDbPersistence()` or `enableMultiTabIndexedDbPersistence()`
  1706. * before setting an index configuration. If IndexedDb is not enabled, any
  1707. * index configuration is ignored.
  1708. *
  1709. * @param firestore - The {@link Firestore} instance to configure indexes for.
  1710. * @param configuration -The index definition.
  1711. * @throws FirestoreError if the JSON format is invalid.
  1712. * @returns A `Promise` that resolves once all indices are successfully
  1713. * configured.
  1714. * @beta
  1715. */
  1716. export declare function setIndexConfiguration(firestore: Firestore, configuration: IndexConfiguration): Promise<void>;
  1717. /**
  1718. * Configures indexing for local query execution. Any previous index
  1719. * configuration is overridden. The `Promise` resolves once the index
  1720. * configuration has been persisted.
  1721. *
  1722. * The index entries themselves are created asynchronously. You can continue to
  1723. * use queries that require indexing even if the indices are not yet available.
  1724. * Query execution will automatically start using the index once the index
  1725. * entries have been written.
  1726. *
  1727. * Indexes are only supported with IndexedDb persistence. Invoke either
  1728. * `enableIndexedDbPersistence()` or `enableMultiTabIndexedDbPersistence()`
  1729. * before setting an index configuration. If IndexedDb is not enabled, any
  1730. * index configuration is ignored.
  1731. *
  1732. * The method accepts the JSON format exported by the Firebase CLI (`firebase
  1733. * firestore:indexes`). If the JSON format is invalid, this method throws an
  1734. * error.
  1735. *
  1736. * @param firestore - The {@link Firestore} instance to configure indexes for.
  1737. * @param json -The JSON format exported by the Firebase CLI.
  1738. * @throws FirestoreError if the JSON format is invalid.
  1739. * @returns A `Promise` that resolves once all indices are successfully
  1740. * configured.
  1741. * @beta
  1742. */
  1743. export declare function setIndexConfiguration(firestore: Firestore, json: string): Promise<void>;
  1744. /**
  1745. * Sets the verbosity of Cloud Firestore logs (debug, error, or silent).
  1746. *
  1747. * @param logLevel - The verbosity you set for activity and error logging. Can
  1748. * be any of the following values:
  1749. *
  1750. * <ul>
  1751. * <li>`debug` for the most verbose logging level, primarily for
  1752. * debugging.</li>
  1753. * <li>`error` to log errors only.</li>
  1754. * <li><code>`silent` to turn off logging.</li>
  1755. * </ul>
  1756. */
  1757. export declare function setLogLevel(logLevel: LogLevel): void;
  1758. /**
  1759. * An options object that configures the behavior of {@link @firebase/firestore/lite#(setDoc:1)}, {@link
  1760. * @firebase/firestore/lite#(WriteBatch.set:1)} and {@link @firebase/firestore/lite#(Transaction.set:1)} calls. These calls can be
  1761. * configured to perform granular merges instead of overwriting the target
  1762. * documents in their entirety by providing a `SetOptions` with `merge: true`.
  1763. *
  1764. * @param merge - Changes the behavior of a `setDoc()` call to only replace the
  1765. * values specified in its data argument. Fields omitted from the `setDoc()`
  1766. * call remain untouched. If your input sets any field to an empty map, all
  1767. * nested fields are overwritten.
  1768. * @param mergeFields - Changes the behavior of `setDoc()` calls to only replace
  1769. * the specified field paths. Any field path that is not specified is ignored
  1770. * and remains untouched. If your input sets any field to an empty map, all
  1771. * nested fields are overwritten.
  1772. */
  1773. export declare type SetOptions = {
  1774. readonly merge?: boolean;
  1775. } | {
  1776. readonly mergeFields?: Array<string | FieldPath>;
  1777. };
  1778. /**
  1779. * Returns true if the provided snapshots are equal.
  1780. *
  1781. * @param left - A snapshot to compare.
  1782. * @param right - A snapshot to compare.
  1783. * @returns true if the snapshots are equal.
  1784. */
  1785. export declare function snapshotEqual<T>(left: DocumentSnapshot<T> | QuerySnapshot<T>, right: DocumentSnapshot<T> | QuerySnapshot<T>): boolean;
  1786. /**
  1787. * An options object that can be passed to {@link (onSnapshot:1)} and {@link
  1788. * QuerySnapshot.docChanges} to control which types of changes to include in the
  1789. * result set.
  1790. */
  1791. export declare interface SnapshotListenOptions {
  1792. /**
  1793. * Include a change even if only the metadata of the query or of a document
  1794. * changed. Default is false.
  1795. */
  1796. readonly includeMetadataChanges?: boolean;
  1797. }
  1798. /**
  1799. * Metadata about a snapshot, describing the state of the snapshot.
  1800. */
  1801. export declare class SnapshotMetadata {
  1802. /**
  1803. * True if the snapshot contains the result of local writes (for example
  1804. * `set()` or `update()` calls) that have not yet been committed to the
  1805. * backend. If your listener has opted into metadata updates (via
  1806. * `SnapshotListenOptions`) you will receive another snapshot with
  1807. * `hasPendingWrites` equal to false once the writes have been committed to
  1808. * the backend.
  1809. */
  1810. readonly hasPendingWrites: boolean;
  1811. /**
  1812. * True if the snapshot was created from cached data rather than guaranteed
  1813. * up-to-date server data. If your listener has opted into metadata updates
  1814. * (via `SnapshotListenOptions`) you will receive another snapshot with
  1815. * `fromCache` set to false once the client has received up-to-date data from
  1816. * the backend.
  1817. */
  1818. readonly fromCache: boolean;
  1819. private constructor();
  1820. /**
  1821. * Returns true if this `SnapshotMetadata` is equal to the provided one.
  1822. *
  1823. * @param other - The `SnapshotMetadata` to compare against.
  1824. * @returns true if this `SnapshotMetadata` is equal to the provided one.
  1825. */
  1826. isEqual(other: SnapshotMetadata): boolean;
  1827. }
  1828. /**
  1829. * Options that configure how data is retrieved from a `DocumentSnapshot` (for
  1830. * example the desired behavior for server timestamps that have not yet been set
  1831. * to their final value).
  1832. */
  1833. export declare interface SnapshotOptions {
  1834. /**
  1835. * If set, controls the return value for server timestamps that have not yet
  1836. * been set to their final value.
  1837. *
  1838. * By specifying 'estimate', pending server timestamps return an estimate
  1839. * based on the local clock. This estimate will differ from the final value
  1840. * and cause these values to change once the server result becomes available.
  1841. *
  1842. * By specifying 'previous', pending timestamps will be ignored and return
  1843. * their previous value instead.
  1844. *
  1845. * If omitted or set to 'none', `null` will be returned by default until the
  1846. * server value becomes available.
  1847. */
  1848. readonly serverTimestamps?: 'estimate' | 'previous' | 'none';
  1849. }
  1850. /**
  1851. * Creates a {@link QueryStartAtConstraint} that modifies the result set to
  1852. * start after the provided document (exclusive). The starting position is
  1853. * relative to the order of the query. The document must contain all of the
  1854. * fields provided in the orderBy of the query.
  1855. *
  1856. * @param snapshot - The snapshot of the document to start after.
  1857. * @returns A {@link QueryStartAtConstraint} to pass to `query()`
  1858. */
  1859. export declare function startAfter(snapshot: DocumentSnapshot<unknown>): QueryStartAtConstraint;
  1860. /**
  1861. * Creates a {@link QueryStartAtConstraint} that modifies the result set to
  1862. * start after the provided fields relative to the order of the query. The order
  1863. * of the field values must match the order of the order by clauses of the query.
  1864. *
  1865. * @param fieldValues - The field values to start this query after, in order
  1866. * of the query's order by.
  1867. * @returns A {@link QueryStartAtConstraint} to pass to `query()`
  1868. */
  1869. export declare function startAfter(...fieldValues: unknown[]): QueryStartAtConstraint;
  1870. /**
  1871. * Creates a {@link QueryStartAtConstraint} that modifies the result set to
  1872. * start at the provided document (inclusive). The starting position is relative
  1873. * to the order of the query. The document must contain all of the fields
  1874. * provided in the `orderBy` of this query.
  1875. *
  1876. * @param snapshot - The snapshot of the document to start at.
  1877. * @returns A {@link QueryStartAtConstraint} to pass to `query()`.
  1878. */
  1879. export declare function startAt(snapshot: DocumentSnapshot<unknown>): QueryStartAtConstraint;
  1880. /**
  1881. * Creates a {@link QueryStartAtConstraint} that modifies the result set to
  1882. * start at the provided fields relative to the order of the query. The order of
  1883. * the field values must match the order of the order by clauses of the query.
  1884. *
  1885. * @param fieldValues - The field values to start this query at, in order
  1886. * of the query's order by.
  1887. * @returns A {@link QueryStartAtConstraint} to pass to `query()`.
  1888. */
  1889. export declare function startAt(...fieldValues: unknown[]): QueryStartAtConstraint;
  1890. /**
  1891. * Represents the state of bundle loading tasks.
  1892. *
  1893. * Both 'Error' and 'Success' are sinking state: task will abort or complete and there will
  1894. * be no more updates after they are reported.
  1895. */
  1896. export declare type TaskState = 'Error' | 'Running' | 'Success';
  1897. /**
  1898. * Terminates the provided {@link Firestore} instance.
  1899. *
  1900. * After calling `terminate()` only the `clearIndexedDbPersistence()` function
  1901. * may be used. Any other function will throw a `FirestoreError`.
  1902. *
  1903. * To restart after termination, create a new instance of FirebaseFirestore with
  1904. * {@link (getFirestore:1)}.
  1905. *
  1906. * Termination does not cancel any pending writes, and any promises that are
  1907. * awaiting a response from the server will not be resolved. If you have
  1908. * persistence enabled, the next time you start this instance, it will resume
  1909. * sending these writes to the server.
  1910. *
  1911. * Note: Under normal circumstances, calling `terminate()` is not required. This
  1912. * function is useful only when you want to force this instance to release all
  1913. * of its resources or in combination with `clearIndexedDbPersistence()` to
  1914. * ensure that all local state is destroyed between test runs.
  1915. *
  1916. * @returns A `Promise` that is resolved when the instance has been successfully
  1917. * terminated.
  1918. */
  1919. export declare function terminate(firestore: Firestore): Promise<void>;
  1920. /**
  1921. * @license
  1922. * Copyright 2017 Google LLC
  1923. *
  1924. * Licensed under the Apache License, Version 2.0 (the "License");
  1925. * you may not use this file except in compliance with the License.
  1926. * You may obtain a copy of the License at
  1927. *
  1928. * http://www.apache.org/licenses/LICENSE-2.0
  1929. *
  1930. * Unless required by applicable law or agreed to in writing, software
  1931. * distributed under the License is distributed on an "AS IS" BASIS,
  1932. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1933. * See the License for the specific language governing permissions and
  1934. * limitations under the License.
  1935. */
  1936. /**
  1937. * A `Timestamp` represents a point in time independent of any time zone or
  1938. * calendar, represented as seconds and fractions of seconds at nanosecond
  1939. * resolution in UTC Epoch time.
  1940. *
  1941. * It is encoded using the Proleptic Gregorian Calendar which extends the
  1942. * Gregorian calendar backwards to year one. It is encoded assuming all minutes
  1943. * are 60 seconds long, i.e. leap seconds are "smeared" so that no leap second
  1944. * table is needed for interpretation. Range is from 0001-01-01T00:00:00Z to
  1945. * 9999-12-31T23:59:59.999999999Z.
  1946. *
  1947. * For examples and further specifications, refer to the
  1948. * {@link https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto | Timestamp definition}.
  1949. */
  1950. export declare class Timestamp {
  1951. /**
  1952. * The number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
  1953. */
  1954. readonly seconds: number;
  1955. /**
  1956. * The fractions of a second at nanosecond resolution.*
  1957. */
  1958. readonly nanoseconds: number;
  1959. /**
  1960. * Creates a new timestamp with the current date, with millisecond precision.
  1961. *
  1962. * @returns a new timestamp representing the current date.
  1963. */
  1964. static now(): Timestamp;
  1965. /**
  1966. * Creates a new timestamp from the given date.
  1967. *
  1968. * @param date - The date to initialize the `Timestamp` from.
  1969. * @returns A new `Timestamp` representing the same point in time as the given
  1970. * date.
  1971. */
  1972. static fromDate(date: Date): Timestamp;
  1973. /**
  1974. * Creates a new timestamp from the given number of milliseconds.
  1975. *
  1976. * @param milliseconds - Number of milliseconds since Unix epoch
  1977. * 1970-01-01T00:00:00Z.
  1978. * @returns A new `Timestamp` representing the same point in time as the given
  1979. * number of milliseconds.
  1980. */
  1981. static fromMillis(milliseconds: number): Timestamp;
  1982. /**
  1983. * Creates a new timestamp.
  1984. *
  1985. * @param seconds - The number of seconds of UTC time since Unix epoch
  1986. * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
  1987. * 9999-12-31T23:59:59Z inclusive.
  1988. * @param nanoseconds - The non-negative fractions of a second at nanosecond
  1989. * resolution. Negative second values with fractions must still have
  1990. * non-negative nanoseconds values that count forward in time. Must be
  1991. * from 0 to 999,999,999 inclusive.
  1992. */
  1993. constructor(
  1994. /**
  1995. * The number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
  1996. */
  1997. seconds: number,
  1998. /**
  1999. * The fractions of a second at nanosecond resolution.*
  2000. */
  2001. nanoseconds: number);
  2002. /**
  2003. * Converts a `Timestamp` to a JavaScript `Date` object. This conversion
  2004. * causes a loss of precision since `Date` objects only support millisecond
  2005. * precision.
  2006. *
  2007. * @returns JavaScript `Date` object representing the same point in time as
  2008. * this `Timestamp`, with millisecond precision.
  2009. */
  2010. toDate(): Date;
  2011. /**
  2012. * Converts a `Timestamp` to a numeric timestamp (in milliseconds since
  2013. * epoch). This operation causes a loss of precision.
  2014. *
  2015. * @returns The point in time corresponding to this timestamp, represented as
  2016. * the number of milliseconds since Unix epoch 1970-01-01T00:00:00Z.
  2017. */
  2018. toMillis(): number;
  2019. /**
  2020. * Returns true if this `Timestamp` is equal to the provided one.
  2021. *
  2022. * @param other - The `Timestamp` to compare against.
  2023. * @returns true if this `Timestamp` is equal to the provided one.
  2024. */
  2025. isEqual(other: Timestamp): boolean;
  2026. /** Returns a textual representation of this `Timestamp`. */
  2027. toString(): string;
  2028. /** Returns a JSON-serializable representation of this `Timestamp`. */
  2029. toJSON(): {
  2030. seconds: number;
  2031. nanoseconds: number;
  2032. };
  2033. /**
  2034. * Converts this object to a primitive string, which allows `Timestamp` objects
  2035. * to be compared using the `>`, `<=`, `>=` and `>` operators.
  2036. */
  2037. valueOf(): string;
  2038. }
  2039. /**
  2040. * A reference to a transaction.
  2041. *
  2042. * The `Transaction` object passed to a transaction's `updateFunction` provides
  2043. * the methods to read and write data within the transaction context. See
  2044. * {@link runTransaction}.
  2045. */
  2046. export declare class Transaction {
  2047. private constructor();
  2048. /**
  2049. * Reads the document referenced by the provided {@link DocumentReference}.
  2050. *
  2051. * @param documentRef - A reference to the document to be read.
  2052. * @returns A `DocumentSnapshot` with the read data.
  2053. */
  2054. get<T>(documentRef: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
  2055. /**
  2056. * Writes to the document referred to by the provided {@link
  2057. * DocumentReference}. If the document does not exist yet, it will be created.
  2058. *
  2059. * @param documentRef - A reference to the document to be set.
  2060. * @param data - An object of the fields and values for the document.
  2061. * @throws Error - If the provided input is not a valid Firestore document.
  2062. * @returns This `Transaction` instance. Used for chaining method calls.
  2063. */
  2064. set<T>(documentRef: DocumentReference<T>, data: WithFieldValue<T>): this;
  2065. /**
  2066. * Writes to the document referred to by the provided {@link
  2067. * DocumentReference}. If the document does not exist yet, it will be created.
  2068. * If you provide `merge` or `mergeFields`, the provided data can be merged
  2069. * into an existing document.
  2070. *
  2071. * @param documentRef - A reference to the document to be set.
  2072. * @param data - An object of the fields and values for the document.
  2073. * @param options - An object to configure the set behavior.
  2074. * @throws Error - If the provided input is not a valid Firestore document.
  2075. * @returns This `Transaction` instance. Used for chaining method calls.
  2076. */
  2077. set<T>(documentRef: DocumentReference<T>, data: PartialWithFieldValue<T>, options: SetOptions): this;
  2078. /**
  2079. * Updates fields in the document referred to by the provided {@link
  2080. * DocumentReference}. The update will fail if applied to a document that does
  2081. * not exist.
  2082. *
  2083. * @param documentRef - A reference to the document to be updated.
  2084. * @param data - An object containing the fields and values with which to
  2085. update the document. Fields can contain dots to reference nested fields
  2086. within the document.
  2087. * @throws Error - If the provided input is not valid Firestore data.
  2088. * @returns This `Transaction` instance. Used for chaining method calls.
  2089. */
  2090. update<T>(documentRef: DocumentReference<T>, data: UpdateData<T>): this;
  2091. /**
  2092. * Updates fields in the document referred to by the provided {@link
  2093. * DocumentReference}. The update will fail if applied to a document that does
  2094. * not exist.
  2095. *
  2096. * Nested fields can be updated by providing dot-separated field path
  2097. * strings or by providing `FieldPath` objects.
  2098. *
  2099. * @param documentRef - A reference to the document to be updated.
  2100. * @param field - The first field to update.
  2101. * @param value - The first value.
  2102. * @param moreFieldsAndValues - Additional key/value pairs.
  2103. * @throws Error - If the provided input is not valid Firestore data.
  2104. * @returns This `Transaction` instance. Used for chaining method calls.
  2105. */
  2106. update(documentRef: DocumentReference<unknown>, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): this;
  2107. /**
  2108. * Deletes the document referred to by the provided {@link DocumentReference}.
  2109. *
  2110. * @param documentRef - A reference to the document to be deleted.
  2111. * @returns This `Transaction` instance. Used for chaining method calls.
  2112. */
  2113. delete(documentRef: DocumentReference<unknown>): this;
  2114. }
  2115. /**
  2116. * @license
  2117. * Copyright 2022 Google LLC
  2118. *
  2119. * Licensed under the Apache License, Version 2.0 (the "License");
  2120. * you may not use this file except in compliance with the License.
  2121. * You may obtain a copy of the License at
  2122. *
  2123. * http://www.apache.org/licenses/LICENSE-2.0
  2124. *
  2125. * Unless required by applicable law or agreed to in writing, software
  2126. * distributed under the License is distributed on an "AS IS" BASIS,
  2127. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2128. * See the License for the specific language governing permissions and
  2129. * limitations under the License.
  2130. */
  2131. /**
  2132. * Options to customize transaction behavior.
  2133. */
  2134. export declare interface TransactionOptions {
  2135. /** Maximum number of attempts to commit, after which transaction fails. Default is 5. */
  2136. readonly maxAttempts?: number;
  2137. }
  2138. /**
  2139. * Given a union type `U = T1 | T2 | ...`, returns an intersected type
  2140. * `(T1 & T2 & ...)`.
  2141. *
  2142. * Uses distributive conditional types and inference from conditional types.
  2143. * This works because multiple candidates for the same type variable in
  2144. * contra-variant positions causes an intersection type to be inferred.
  2145. * https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-inference-in-conditional-types
  2146. * https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type
  2147. */
  2148. export declare type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
  2149. /**
  2150. * A function returned by `onSnapshot()` that removes the listener when invoked.
  2151. */
  2152. export declare interface Unsubscribe {
  2153. /** Removes the listener when invoked. */
  2154. (): void;
  2155. }
  2156. /**
  2157. * Update data (for use with {@link (updateDoc:1)}) that consists of field paths
  2158. * (e.g. 'foo' or 'foo.baz') mapped to values. Fields that contain dots
  2159. * reference nested fields within the document. FieldValues can be passed in
  2160. * as property values.
  2161. */
  2162. export declare type UpdateData<T> = T extends Primitive ? T : T extends {} ? {
  2163. [K in keyof T]?: UpdateData<T[K]> | FieldValue;
  2164. } & NestedUpdateFields<T> : Partial<T>;
  2165. /**
  2166. * Updates fields in the document referred to by the specified
  2167. * `DocumentReference`. The update will fail if applied to a document that does
  2168. * not exist.
  2169. *
  2170. * @param reference - A reference to the document to update.
  2171. * @param data - An object containing the fields and values with which to
  2172. * update the document. Fields can contain dots to reference nested fields
  2173. * within the document.
  2174. * @returns A `Promise` resolved once the data has been successfully written
  2175. * to the backend (note that it won't resolve while you're offline).
  2176. */
  2177. export declare function updateDoc<T>(reference: DocumentReference<T>, data: UpdateData<T>): Promise<void>;
  2178. /**
  2179. * Updates fields in the document referred to by the specified
  2180. * `DocumentReference` The update will fail if applied to a document that does
  2181. * not exist.
  2182. *
  2183. * Nested fields can be updated by providing dot-separated field path
  2184. * strings or by providing `FieldPath` objects.
  2185. *
  2186. * @param reference - A reference to the document to update.
  2187. * @param field - The first field to update.
  2188. * @param value - The first value.
  2189. * @param moreFieldsAndValues - Additional key value pairs.
  2190. * @returns A `Promise` resolved once the data has been successfully written
  2191. * to the backend (note that it won't resolve while you're offline).
  2192. */
  2193. export declare function updateDoc(reference: DocumentReference<unknown>, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): Promise<void>;
  2194. /**
  2195. * Waits until all currently pending writes for the active user have been
  2196. * acknowledged by the backend.
  2197. *
  2198. * The returned promise resolves immediately if there are no outstanding writes.
  2199. * Otherwise, the promise waits for all previously issued writes (including
  2200. * those written in a previous app session), but it does not wait for writes
  2201. * that were added after the function is called. If you want to wait for
  2202. * additional writes, call `waitForPendingWrites()` again.
  2203. *
  2204. * Any outstanding `waitForPendingWrites()` promises are rejected during user
  2205. * changes.
  2206. *
  2207. * @returns A `Promise` which resolves when all currently pending writes have been
  2208. * acknowledged by the backend.
  2209. */
  2210. export declare function waitForPendingWrites(firestore: Firestore): Promise<void>;
  2211. /**
  2212. * Creates a {@link QueryFieldFilterConstraint} that enforces that documents
  2213. * must contain the specified field and that the value should satisfy the
  2214. * relation constraint provided.
  2215. *
  2216. * @param fieldPath - The path to compare
  2217. * @param opStr - The operation string (e.g "&lt;", "&lt;=", "==", "&lt;",
  2218. * "&lt;=", "!=").
  2219. * @param value - The value for comparison
  2220. * @returns The created {@link QueryFieldFilterConstraint}.
  2221. */
  2222. export declare function where(fieldPath: string | FieldPath, opStr: WhereFilterOp, value: unknown): QueryFieldFilterConstraint;
  2223. /**
  2224. * Filter conditions in a {@link where} clause are specified using the
  2225. * strings '&lt;', '&lt;=', '==', '!=', '&gt;=', '&gt;', 'array-contains', 'in',
  2226. * 'array-contains-any', and 'not-in'.
  2227. */
  2228. export declare type WhereFilterOp = '<' | '<=' | '==' | '!=' | '>=' | '>' | 'array-contains' | 'in' | 'array-contains-any' | 'not-in';
  2229. /**
  2230. * Allows FieldValues to be passed in as a property value while maintaining
  2231. * type safety.
  2232. */
  2233. export declare type WithFieldValue<T> = T | (T extends Primitive ? T : T extends {} ? {
  2234. [K in keyof T]: WithFieldValue<T[K]> | FieldValue;
  2235. } : never);
  2236. /**
  2237. * A write batch, used to perform multiple writes as a single atomic unit.
  2238. *
  2239. * A `WriteBatch` object can be acquired by calling {@link writeBatch}. It
  2240. * provides methods for adding writes to the write batch. None of the writes
  2241. * will be committed (or visible locally) until {@link WriteBatch.commit} is
  2242. * called.
  2243. */
  2244. export declare class WriteBatch {
  2245. private constructor();
  2246. /**
  2247. * Writes to the document referred to by the provided {@link
  2248. * DocumentReference}. If the document does not exist yet, it will be created.
  2249. *
  2250. * @param documentRef - A reference to the document to be set.
  2251. * @param data - An object of the fields and values for the document.
  2252. * @returns This `WriteBatch` instance. Used for chaining method calls.
  2253. */
  2254. set<T>(documentRef: DocumentReference<T>, data: WithFieldValue<T>): WriteBatch;
  2255. /**
  2256. * Writes to the document referred to by the provided {@link
  2257. * DocumentReference}. If the document does not exist yet, it will be created.
  2258. * If you provide `merge` or `mergeFields`, the provided data can be merged
  2259. * into an existing document.
  2260. *
  2261. * @param documentRef - A reference to the document to be set.
  2262. * @param data - An object of the fields and values for the document.
  2263. * @param options - An object to configure the set behavior.
  2264. * @throws Error - If the provided input is not a valid Firestore document.
  2265. * @returns This `WriteBatch` instance. Used for chaining method calls.
  2266. */
  2267. set<T>(documentRef: DocumentReference<T>, data: PartialWithFieldValue<T>, options: SetOptions): WriteBatch;
  2268. /**
  2269. * Updates fields in the document referred to by the provided {@link
  2270. * DocumentReference}. The update will fail if applied to a document that does
  2271. * not exist.
  2272. *
  2273. * @param documentRef - A reference to the document to be updated.
  2274. * @param data - An object containing the fields and values with which to
  2275. * update the document. Fields can contain dots to reference nested fields
  2276. * within the document.
  2277. * @throws Error - If the provided input is not valid Firestore data.
  2278. * @returns This `WriteBatch` instance. Used for chaining method calls.
  2279. */
  2280. update<T>(documentRef: DocumentReference<T>, data: UpdateData<T>): WriteBatch;
  2281. /**
  2282. * Updates fields in the document referred to by this {@link
  2283. * DocumentReference}. The update will fail if applied to a document that does
  2284. * not exist.
  2285. *
  2286. * Nested fields can be update by providing dot-separated field path strings
  2287. * or by providing `FieldPath` objects.
  2288. *
  2289. * @param documentRef - A reference to the document to be updated.
  2290. * @param field - The first field to update.
  2291. * @param value - The first value.
  2292. * @param moreFieldsAndValues - Additional key value pairs.
  2293. * @throws Error - If the provided input is not valid Firestore data.
  2294. * @returns This `WriteBatch` instance. Used for chaining method calls.
  2295. */
  2296. update(documentRef: DocumentReference<unknown>, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): WriteBatch;
  2297. /**
  2298. * Deletes the document referred to by the provided {@link DocumentReference}.
  2299. *
  2300. * @param documentRef - A reference to the document to be deleted.
  2301. * @returns This `WriteBatch` instance. Used for chaining method calls.
  2302. */
  2303. delete(documentRef: DocumentReference<unknown>): WriteBatch;
  2304. /**
  2305. * Commits all of the writes in this write batch as a single atomic unit.
  2306. *
  2307. * The result of these writes will only be reflected in document reads that
  2308. * occur after the returned promise resolves. If the client is offline, the
  2309. * write fails. If you would like to see local modifications or buffer writes
  2310. * until the client is online, use the full Firestore SDK.
  2311. *
  2312. * @returns A `Promise` resolved once all of the writes in the batch have been
  2313. * successfully written to the backend as an atomic unit (note that it won't
  2314. * resolve while you're offline).
  2315. */
  2316. commit(): Promise<void>;
  2317. }
  2318. /**
  2319. * Creates a write batch, used for performing multiple writes as a single
  2320. * atomic operation. The maximum number of writes allowed in a single {@link WriteBatch}
  2321. * is 500.
  2322. *
  2323. * Unlike transactions, write batches are persisted offline and therefore are
  2324. * preferable when you don't need to condition your writes on read data.
  2325. *
  2326. * @returns A {@link WriteBatch} that can be used to atomically execute multiple
  2327. * writes.
  2328. */
  2329. export declare function writeBatch(firestore: Firestore): WriteBatch;
  2330. export {};