diff --git a/.changeset/hungry-zebras-laugh.md b/.changeset/hungry-zebras-laugh.md new file mode 100644 index 00000000000..6aee2260031 --- /dev/null +++ b/.changeset/hungry-zebras-laugh.md @@ -0,0 +1,5 @@ +--- +"@firebase/firestore": minor +--- + +Expose the MultiDB API for Public Preview. [#7356](https://github.com/firebase/firebase-js-sdk/pull/7356) diff --git a/common/api-review/firestore-lite.api.md b/common/api-review/firestore-lite.api.md index 35802afacb7..d761c7998db 100644 --- a/common/api-review/firestore-lite.api.md +++ b/common/api-review/firestore-lite.api.md @@ -218,12 +218,21 @@ export function getFirestore(): Firestore; // @public export function getFirestore(app: FirebaseApp): Firestore; +// @beta +export function getFirestore(databaseId: string): Firestore; + +// @beta +export function getFirestore(app: FirebaseApp, databaseId: string): Firestore; + // @public export function increment(n: number): FieldValue; // @public export function initializeFirestore(app: FirebaseApp, settings: Settings): Firestore; +// @beta +export function initializeFirestore(app: FirebaseApp, settings: Settings, databaseId?: string): Firestore; + // @public export function limit(limit: number): QueryLimitConstraint; diff --git a/common/api-review/firestore.api.md b/common/api-review/firestore.api.md index 580320b0aa3..b9958f19560 100644 --- a/common/api-review/firestore.api.md +++ b/common/api-review/firestore.api.md @@ -277,9 +277,15 @@ export function getDocsFromServer(query: Query): Promise> // @public export function getFirestore(app: FirebaseApp): Firestore; +// @beta +export function getFirestore(databaseId: string): Firestore; + // @public export function getFirestore(): Firestore; +// @beta +export function getFirestore(app: FirebaseApp, databaseId: string): Firestore; + // @public export function increment(n: number): FieldValue; diff --git a/docs-devsite/firestore_.md b/docs-devsite/firestore_.md index 41b85f1f3eb..a0c52be3bc0 100644 --- a/docs-devsite/firestore_.md +++ b/docs-devsite/firestore_.md @@ -17,6 +17,7 @@ https://github.com/firebase/firebase-js-sdk | --- | --- | | function(app...) | | [getFirestore(app)](./firestore_.md#getfirestore) | Returns the existing default [Firestore](./firestore_.firestore.md#firestore_class) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with default settings. | +| [getFirestore(app, databaseId)](./firestore_.md#getfirestore) | (BETA) Returns the existing default [Firestore](./firestore_.firestore.md#firestore_class) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with default settings. | | [initializeFirestore(app, settings, databaseId)](./firestore_.md#initializefirestore) | Initializes a new instance of [Firestore](./firestore_.firestore.md#firestore_class) with the provided settings. Can only be called before any other function, including [getFirestore()](./firestore_.md#getfirestore). If the custom settings are empty, this function is equivalent to calling [getFirestore()](./firestore_.md#getfirestore). | | function(firestore...) | | [clearIndexedDbPersistence(firestore)](./firestore_.md#clearindexeddbpersistence) | Clears the persistent storage. This includes pending writes and cached documents.Must be called while the [Firestore](./firestore_.firestore.md#firestore_class) instance is not started (after the app is terminated or when the app is first initialized). On startup, this function must be called before other functions (other than [initializeFirestore()](./firestore_.md#initializefirestore) or [getFirestore()](./firestore_.md#getfirestore))). If the [Firestore](./firestore_.firestore.md#firestore_class) instance is still running, the promise will be rejected with the error code of failed-precondition.Note: clearIndexedDbPersistence() is primarily intended to help write reliable tests that use Cloud Firestore. It uses an efficient mechanism for dropping existing data but does not attempt to securely overwrite or otherwise make cached data unrecoverable. For applications that are sensitive to the disclosure of cached data in between user sessions, we strongly recommend not enabling persistence at all. | @@ -45,6 +46,8 @@ https://github.com/firebase/firebase-js-sdk | [memoryEagerGarbageCollector()](./firestore_.md#memoryeagergarbagecollector) | Creates an instance of MemoryEagerGarbageCollector. This is also the default garbage collector unless it is explicitly specified otherwise. | | [persistentMultipleTabManager()](./firestore_.md#persistentmultipletabmanager) | Creates an instance of PersistentMultipleTabManager. | | [serverTimestamp()](./firestore_.md#servertimestamp) | Returns a sentinel used with [setDoc()](./firestore_lite.md#setdoc) or [updateDoc()](./firestore_lite.md#updatedoc) to include a server-generated timestamp in the written data. | +| function(databaseId...) | +| [getFirestore(databaseId)](./firestore_.md#getfirestore) | (BETA) Returns the existing [Firestore](./firestore_.firestore.md#firestore_class) instance that is associated with the default [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with default settings. | | function(elements...) | | [arrayRemove(elements)](./firestore_.md#arrayremove) | Returns a special value that can be used with [setDoc()](./firestore_.md#setdoc) or that tells the server to remove the given elements from any array value that already exists on the server. All instances of each element specified will be removed from the array. If the field being modified is not already an array it will be overwritten with an empty array. | | [arrayUnion(elements)](./firestore_.md#arrayunion) | Returns a special value that can be used with [setDoc()](./firestore_lite.md#setdoc) or [updateDoc()](./firestore_lite.md#updatedoc) that tells the server to union the given elements with any array value that already exists on the server. Each specified element that doesn't already exist in the array will be added to the end. If the field being modified is not already an array it will be overwritten with an array containing exactly the specified elements. | @@ -226,6 +229,32 @@ export declare function getFirestore(app: FirebaseApp): Firestore; The [Firestore](./firestore_.firestore.md#firestore_class) instance of the provided app. +## getFirestore() + +> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +Returns the existing default [Firestore](./firestore_.firestore.md#firestore_class) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with default settings. + +Signature: + +```typescript +export declare function getFirestore(app: FirebaseApp, databaseId: string): Firestore; +``` + +### Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| app | [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) instance that the returned [Firestore](./firestore_.firestore.md#firestore_class) instance is associated with. | +| databaseId | string | The name of the database. | + +Returns: + +[Firestore](./firestore_.firestore.md#firestore_class) + +The [Firestore](./firestore_.firestore.md#firestore_class) instance of the provided app. + ## initializeFirestore() Initializes a new instance of [Firestore](./firestore_.firestore.md#firestore_class) with the provided settings. Can only be called before any other function, including [getFirestore()](./firestore_.md#getfirestore). If the custom settings are empty, this function is equivalent to calling [getFirestore()](./firestore_.md#getfirestore). @@ -242,7 +271,7 @@ export declare function initializeFirestore(app: FirebaseApp, settings: Firestor | --- | --- | --- | | app | [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) with which the [Firestore](./firestore_.firestore.md#firestore_class) instance will be associated. | | settings | [FirestoreSettings](./firestore_.firestoresettings.md#firestoresettings_interface) | A settings object to configure the [Firestore](./firestore_.firestore.md#firestore_class) instance. | -| databaseId | string | The name of database. | +| databaseId | string | The name of the database. | Returns: @@ -855,6 +884,31 @@ export declare function serverTimestamp(): FieldValue; [FieldValue](./firestore_.fieldvalue.md#fieldvalue_class) +## getFirestore() + +> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +Returns the existing [Firestore](./firestore_.firestore.md#firestore_class) instance that is associated with the default [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with default settings. + +Signature: + +```typescript +export declare function getFirestore(databaseId: string): Firestore; +``` + +### Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| databaseId | string | The name of the database. | + +Returns: + +[Firestore](./firestore_.firestore.md#firestore_class) + +The [Firestore](./firestore_.firestore.md#firestore_class) instance of the provided app. + ## arrayRemove() Returns a special value that can be used with [setDoc()](./firestore_.md#setdoc) or that tells the server to remove the given elements from any array value that already exists on the server. All instances of each element specified will be removed from the array. If the field being modified is not already an array it will be overwritten with an empty array. diff --git a/docs-devsite/firestore_lite.md b/docs-devsite/firestore_lite.md index b0ec302e722..adb6063858c 100644 --- a/docs-devsite/firestore_lite.md +++ b/docs-devsite/firestore_lite.md @@ -17,7 +17,9 @@ https://github.com/firebase/firebase-js-sdk | --- | --- | | function(app...) | | [getFirestore(app)](./firestore_lite.md#getfirestore) | Returns the existing default [Firestore](./firestore_.firestore.md#firestore_class) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with default settings. | +| [getFirestore(app, databaseId)](./firestore_lite.md#getfirestore) | (BETA) Returns the existing [Firestore](./firestore_.firestore.md#firestore_class) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with default settings. | | [initializeFirestore(app, settings)](./firestore_lite.md#initializefirestore) | Initializes a new instance of Cloud Firestore with the provided settings. Can only be called before any other functions, including [getFirestore()](./firestore_.md#getfirestore). If the custom settings are empty, this function is equivalent to calling [getFirestore()](./firestore_.md#getfirestore). | +| [initializeFirestore(app, settings, databaseId)](./firestore_lite.md#initializefirestore) | (BETA) Initializes a new instance of Cloud Firestore with the provided settings. Can only be called before any other functions, including [getFirestore()](./firestore_.md#getfirestore). If the custom settings are empty, this function is equivalent to calling [getFirestore()](./firestore_.md#getfirestore). | | function(firestore...) | | [collection(firestore, path, pathSegments)](./firestore_lite.md#collection) | Gets a CollectionReference instance that refers to the collection at the specified absolute path. | | [collectionGroup(firestore, collectionId)](./firestore_lite.md#collectiongroup) | Creates and returns a new Query instance that includes all documents in the database that are contained in a collection or subcollection with the given collectionId. | @@ -31,6 +33,8 @@ https://github.com/firebase/firebase-js-sdk | [documentId()](./firestore_lite.md#documentid) | Returns a special sentinel FieldPath to refer to the ID of a document. It can be used in queries to sort or filter by the document ID. | | [getFirestore()](./firestore_lite.md#getfirestore) | Returns the existing default [Firestore](./firestore_.firestore.md#firestore_class) instance that is associated with the default [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with default settings. | | [serverTimestamp()](./firestore_lite.md#servertimestamp) | Returns a sentinel used with [setDoc()](./firestore_lite.md#setdoc) or [updateDoc()](./firestore_lite.md#updatedoc) to include a server-generated timestamp in the written data. | +| function(databaseId...) | +| [getFirestore(databaseId)](./firestore_lite.md#getfirestore) | (BETA) Returns the existing [Firestore](./firestore_.firestore.md#firestore_class) instance that is associated with the default [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with default settings. | | function(elements...) | | [arrayRemove(elements)](./firestore_lite.md#arrayremove) | Returns a special value that can be used with [setDoc()](./firestore_.md#setdoc) or that tells the server to remove the given elements from any array value that already exists on the server. All instances of each element specified will be removed from the array. If the field being modified is not already an array it will be overwritten with an empty array. | | [arrayUnion(elements)](./firestore_lite.md#arrayunion) | Returns a special value that can be used with [setDoc()](./firestore_lite.md#setdoc) or [updateDoc()](./firestore_lite.md#updatedoc) that tells the server to union the given elements with any array value that already exists on the server. Each specified element that doesn't already exist in the array will be added to the end. If the field being modified is not already an array it will be overwritten with an array containing exactly the specified elements. | @@ -163,6 +167,32 @@ export declare function getFirestore(app: FirebaseApp): Firestore; The [Firestore](./firestore_.firestore.md#firestore_class) instance of the provided app. +## getFirestore() + +> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +Returns the existing [Firestore](./firestore_.firestore.md#firestore_class) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with default settings. + +Signature: + +```typescript +export declare function getFirestore(app: FirebaseApp, databaseId: string): Firestore; +``` + +### Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| app | [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) instance that the returned [Firestore](./firestore_.firestore.md#firestore_class) instance is associated with. | +| databaseId | string | The name of the database. | + +Returns: + +[Firestore](./firestore_lite.firestore.md#firestore_class) + +The [Firestore](./firestore_.firestore.md#firestore_class) instance of the provided app. + ## initializeFirestore() Initializes a new instance of Cloud Firestore with the provided settings. Can only be called before any other functions, including [getFirestore()](./firestore_.md#getfirestore). If the custom settings are empty, this function is equivalent to calling [getFirestore()](./firestore_.md#getfirestore). @@ -186,6 +216,33 @@ export declare function initializeFirestore(app: FirebaseApp, settings: Settings A newly initialized `Firestore` instance. +## initializeFirestore() + +> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +Initializes a new instance of Cloud Firestore with the provided settings. Can only be called before any other functions, including [getFirestore()](./firestore_.md#getfirestore). If the custom settings are empty, this function is equivalent to calling [getFirestore()](./firestore_.md#getfirestore). + +Signature: + +```typescript +export declare function initializeFirestore(app: FirebaseApp, settings: Settings, databaseId?: string): Firestore; +``` + +### Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| app | [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) with which the Firestore instance will be associated. | +| settings | [Settings](./firestore_lite.settings.md#settings_interface) | A settings object to configure the Firestore instance. | +| databaseId | string | The name of the database. | + +Returns: + +[Firestore](./firestore_lite.firestore.md#firestore_class) + +A newly initialized `Firestore` instance. + ## collection() Gets a `CollectionReference` instance that refers to the collection at the specified absolute path. @@ -424,6 +481,31 @@ export declare function serverTimestamp(): FieldValue; [FieldValue](./firestore_lite.fieldvalue.md#fieldvalue_class) +## getFirestore() + +> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +Returns the existing [Firestore](./firestore_.firestore.md#firestore_class) instance that is associated with the default [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with default settings. + +Signature: + +```typescript +export declare function getFirestore(databaseId: string): Firestore; +``` + +### Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| databaseId | string | The name of the database. | + +Returns: + +[Firestore](./firestore_lite.firestore.md#firestore_class) + +The [Firestore](./firestore_.firestore.md#firestore_class) instance of the provided app. + ## arrayRemove() Returns a special value that can be used with [setDoc()](./firestore_.md#setdoc) or that tells the server to remove the given elements from any array value that already exists on the server. All instances of each element specified will be removed from the array. If the field being modified is not already an array it will be overwritten with an empty array. diff --git a/packages/firestore/src/api/database.ts b/packages/firestore/src/api/database.ts index 311e665e048..e4d0bdd4289 100644 --- a/packages/firestore/src/api/database.ts +++ b/packages/firestore/src/api/database.ts @@ -134,7 +134,7 @@ export class Firestore extends LiteFirestore { * @param app - The {@link @firebase/app#FirebaseApp} with which the {@link Firestore} instance will * be associated. * @param settings - A settings object to configure the {@link Firestore} instance. - * @param databaseId - The name of database. + * @param databaseId - The name of the database. * @returns A newly initialized {@link Firestore} instance. */ export function initializeFirestore( @@ -210,9 +210,9 @@ export function getFirestore(app: FirebaseApp): Firestore; * default {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new * instance with default settings. * - * @param databaseId - The name of database. + * @param databaseId - The name of the database. * @returns The {@link Firestore} instance of the provided app. - * @internal + * @beta */ export function getFirestore(databaseId: string): Firestore; /** @@ -230,9 +230,9 @@ export function getFirestore(): Firestore; * * @param app - The {@link @firebase/app#FirebaseApp} instance that the returned {@link Firestore} * instance is associated with. - * @param databaseId - The name of database. + * @param databaseId - The name of the database. * @returns The {@link Firestore} instance of the provided app. - * @internal + * @beta */ export function getFirestore(app: FirebaseApp, databaseId: string): Firestore; export function getFirestore( diff --git a/packages/firestore/src/lite-api/database.ts b/packages/firestore/src/lite-api/database.ts index 22764282551..3cc73f6290d 100644 --- a/packages/firestore/src/lite-api/database.ts +++ b/packages/firestore/src/lite-api/database.ts @@ -184,9 +184,9 @@ export function initializeFirestore( * @param app - The {@link @firebase/app#FirebaseApp} with which the `Firestore` instance will * be associated. * @param settings - A settings object to configure the `Firestore` instance. - * @param databaseId - The name of database. + * @param databaseId - The name of the database. * @returns A newly initialized `Firestore` instance. - * @internal + * @beta */ export function initializeFirestore( app: FirebaseApp, @@ -239,9 +239,9 @@ export function getFirestore(app: FirebaseApp): Firestore; * default {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new * instance with default settings. * - * @param databaseId - The name of database. + * @param databaseId - The name of the database. * @returns The {@link Firestore} instance of the provided app. - * @internal + * @beta */ export function getFirestore(databaseId: string): Firestore; /** @@ -251,9 +251,9 @@ export function getFirestore(databaseId: string): Firestore; * * @param app - The {@link @firebase/app#FirebaseApp} instance that the returned {@link Firestore} * instance is associated with. - * @param databaseId - The name of database. + * @param databaseId - The name of the database. * @returns The {@link Firestore} instance of the provided app. - * @internal + * @beta */ export function getFirestore(app: FirebaseApp, databaseId: string): Firestore; export function getFirestore(