From d6eaa63992a921db979678b2a83fbc60a9a3e2e4 Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Fri, 19 May 2023 14:10:41 -0400 Subject: [PATCH 01/10] Add a second type parameter to FirestoreDataConverter to fix the updateDoc() typing issue --- packages/firestore/src/api/aggregate.ts | 51 ++-- packages/firestore/src/api/reference_impl.ts | 215 ++++++++++------ packages/firestore/src/api/snapshot.ts | 95 ++++--- packages/firestore/src/api/transaction.ts | 8 +- .../firestore/src/core/firestore_client.ts | 2 + packages/firestore/src/lite-api/aggregate.ts | 58 +++-- .../firestore/src/lite-api/aggregate_types.ts | 16 +- packages/firestore/src/lite-api/query.ts | 71 +++-- packages/firestore/src/lite-api/reference.ts | 242 +++++++++++------- .../firestore/src/lite-api/reference_impl.ts | 92 ++++--- packages/firestore/src/lite-api/snapshot.ts | 75 ++++-- .../firestore/src/lite-api/transaction.ts | 45 ++-- .../src/lite-api/user_data_reader.ts | 15 +- .../firestore/src/lite-api/write_batch.ts | 51 ++-- .../firestore/test/lite/integration.test.ts | 79 +++--- 15 files changed, 689 insertions(+), 426 deletions(-) diff --git a/packages/firestore/src/api/aggregate.ts b/packages/firestore/src/api/aggregate.ts index 0b9dfd353e3..9628beac32c 100644 --- a/packages/firestore/src/api/aggregate.ts +++ b/packages/firestore/src/api/aggregate.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { AggregateField, AggregateSpec, Query } from '../api'; +import { AggregateField, AggregateSpec, DocumentData, Query } from '../api'; import { AggregateImpl } from '../core/aggregate'; import { firestoreClientRunAggregateQuery } from '../core/firestore_client'; import { count } from '../lite-api/aggregate'; @@ -56,9 +56,18 @@ export { * retrieved from `snapshot.data().count`, where `snapshot` is the * `AggregateQuerySnapshot` to which the returned Promise resolves. */ -export function getCountFromServer( - query: Query -): Promise }>> { +export function getCountFromServer< + AppModelType, + DbModelType extends DocumentData +>( + query: Query +): Promise< + AggregateQuerySnapshot< + { count: AggregateField }, + AppModelType, + DbModelType + > +> { const countQuerySpec: { count: AggregateField } = { count: count() }; @@ -100,10 +109,16 @@ export function getCountFromServer( * ``` * @internal TODO (sum/avg) remove when public */ -export function getAggregateFromServer( - query: Query, - aggregateSpec: T -): Promise> { +export function getAggregateFromServer< + AggregateSpecType extends AggregateSpec, + AppModelType, + DbModelType extends DocumentData +>( + query: Query, + aggregateSpec: AggregateSpecType +): Promise< + AggregateQuerySnapshot +> { const firestore = cast(query.firestore, Firestore); const client = ensureFirestoreConfigured(firestore); @@ -132,16 +147,20 @@ export function getAggregateFromServer( * @param aggregateResult Core aggregation result * @internal */ -function convertToAggregateQuerySnapshot( +function convertToAggregateQuerySnapshot< + AggregateSpecType extends AggregateSpec, + AppModelType, + DbModelType extends DocumentData +>( firestore: Firestore, - query: Query, + query: Query, aggregateResult: ApiClientObjectMap -): AggregateQuerySnapshot { +): AggregateQuerySnapshot { const userDataWriter = new ExpUserDataWriter(firestore); - const querySnapshot = new AggregateQuerySnapshot( - query, - userDataWriter, - aggregateResult - ); + const querySnapshot = new AggregateQuerySnapshot< + AggregateSpecType, + AppModelType, + DbModelType + >(query, userDataWriter, aggregateResult); return querySnapshot; } diff --git a/packages/firestore/src/api/reference_impl.ts b/packages/firestore/src/api/reference_impl.ts index eabd0fb0021..13cfb09f518 100644 --- a/packages/firestore/src/api/reference_impl.ts +++ b/packages/firestore/src/api/reference_impl.ts @@ -41,6 +41,7 @@ import { validateHasExplicitOrderByForLimitToLast } from '../lite-api/query'; import { CollectionReference, doc, + DocumentData, DocumentReference, PartialWithFieldValue, Query, @@ -91,10 +92,13 @@ export interface SnapshotListenOptions { * @returns A Promise resolved with a `DocumentSnapshot` containing the * current document contents. */ -export function getDoc( - reference: DocumentReference -): Promise> { - reference = cast>(reference, DocumentReference); +export function getDoc( + reference: DocumentReference +): Promise> { + reference = cast>( + reference, + DocumentReference + ); const firestore = cast(reference.firestore, Firestore); const client = ensureFirestoreConfigured(firestore); @@ -126,17 +130,20 @@ export class ExpUserDataWriter extends AbstractUserDataWriter { * @returns A `Promise` resolved with a `DocumentSnapshot` containing the * current document contents. */ -export function getDocFromCache( - reference: DocumentReference -): Promise> { - reference = cast>(reference, DocumentReference); +export function getDocFromCache( + reference: DocumentReference +): Promise> { + reference = cast>( + reference, + DocumentReference + ); const firestore = cast(reference.firestore, Firestore); const client = ensureFirestoreConfigured(firestore); const userDataWriter = new ExpUserDataWriter(firestore); return firestoreClientGetDocumentFromLocalCache(client, reference._key).then( doc => - new DocumentSnapshot( + new DocumentSnapshot( firestore, userDataWriter, reference._key, @@ -157,10 +164,16 @@ export function getDocFromCache( * @returns A `Promise` resolved with a `DocumentSnapshot` containing the * current document contents. */ -export function getDocFromServer( - reference: DocumentReference -): Promise> { - reference = cast>(reference, DocumentReference); +export function getDocFromServer< + AppModelType, + DbModelType extends DocumentData +>( + reference: DocumentReference +): Promise> { + reference = cast>( + reference, + DocumentReference + ); const firestore = cast(reference.firestore, Firestore); const client = ensureFirestoreConfigured(firestore); @@ -179,8 +192,10 @@ export function getDocFromServer( * * @returns A `Promise` that will be resolved with the results of the query. */ -export function getDocs(query: Query): Promise> { - query = cast>(query, Query); +export function getDocs( + query: Query +): Promise> { + query = cast>(query, Query); const firestore = cast(query.firestore, Firestore); const client = ensureFirestoreConfigured(firestore); const userDataWriter = new ExpUserDataWriter(firestore); @@ -190,7 +205,13 @@ export function getDocs(query: Query): Promise> { client, query._query ).then( - snapshot => new QuerySnapshot(firestore, userDataWriter, query, snapshot) + snapshot => + new QuerySnapshot( + firestore, + userDataWriter, + query, + snapshot + ) ); } @@ -201,16 +222,25 @@ export function getDocs(query: Query): Promise> { * * @returns A `Promise` that will be resolved with the results of the query. */ -export function getDocsFromCache( - query: Query -): Promise> { - query = cast>(query, Query); +export function getDocsFromCache< + AppModelType, + DbModelType extends DocumentData +>( + query: Query +): Promise> { + query = cast>(query, Query); const firestore = cast(query.firestore, Firestore); const client = ensureFirestoreConfigured(firestore); const userDataWriter = new ExpUserDataWriter(firestore); return firestoreClientGetDocumentsFromLocalCache(client, query._query).then( - snapshot => new QuerySnapshot(firestore, userDataWriter, query, snapshot) + snapshot => + new QuerySnapshot( + firestore, + userDataWriter, + query, + snapshot + ) ); } @@ -220,10 +250,13 @@ export function getDocsFromCache( * * @returns A `Promise` that will be resolved with the results of the query. */ -export function getDocsFromServer( - query: Query -): Promise> { - query = cast>(query, Query); +export function getDocsFromServer< + AppModelType, + DbModelType extends DocumentData +>( + query: Query +): Promise> { + query = cast>(query, Query); const firestore = cast(query.firestore, Firestore); const client = ensureFirestoreConfigured(firestore); const userDataWriter = new ExpUserDataWriter(firestore); @@ -244,9 +277,9 @@ export function getDocsFromServer( * @returns A `Promise` resolved once the data has been successfully written * to the backend (note that it won't resolve while you're offline). */ -export function setDoc( - reference: DocumentReference, - data: WithFieldValue +export function setDoc( + reference: DocumentReference, + data: WithFieldValue ): Promise; /** * Writes to the document referred to by the specified `DocumentReference`. If @@ -259,22 +292,25 @@ export function setDoc( * @returns A Promise resolved once the data has been successfully written * to the backend (note that it won't resolve while you're offline). */ -export function setDoc( - reference: DocumentReference, - data: PartialWithFieldValue, +export function setDoc( + reference: DocumentReference, + data: PartialWithFieldValue, options: SetOptions ): Promise; -export function setDoc( - reference: DocumentReference, - data: PartialWithFieldValue, +export function setDoc( + reference: DocumentReference, + data: PartialWithFieldValue, options?: SetOptions ): Promise { - reference = cast>(reference, DocumentReference); + reference = cast>( + reference, + DocumentReference + ); const firestore = cast(reference.firestore, Firestore); const convertedValue = applyFirestoreDataConverter( reference.converter, - data as WithFieldValue, + data as WithFieldValue, options ); const dataReader = newUserDataReader(firestore); @@ -303,9 +339,9 @@ export function setDoc( * @returns A `Promise` resolved once the data has been successfully written * to the backend (note that it won't resolve while you're offline). */ -export function updateDoc( - reference: DocumentReference, - data: UpdateData +export function updateDoc( + reference: DocumentReference, + data: UpdateData ): Promise; /** * Updates fields in the document referred to by the specified @@ -322,19 +358,22 @@ export function updateDoc( * @returns A `Promise` resolved once the data has been successfully written * to the backend (note that it won't resolve while you're offline). */ -export function updateDoc( - reference: DocumentReference, +export function updateDoc( + reference: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[] ): Promise; -export function updateDoc( +export function updateDoc( reference: DocumentReference, - fieldOrUpdateData: string | FieldPath | UpdateData, + fieldOrUpdateData: string | FieldPath | UpdateData, value?: unknown, ...moreFieldsAndValues: unknown[] ): Promise { - reference = cast>(reference, DocumentReference); + reference = cast>( + reference, + DocumentReference + ); const firestore = cast(reference.firestore, Firestore); const dataReader = newUserDataReader(firestore); @@ -376,8 +415,8 @@ export function updateDoc( * @returns A Promise resolved once the document has been successfully * deleted from the backend (note that it won't resolve while you're offline). */ -export function deleteDoc( - reference: DocumentReference +export function deleteDoc( + reference: DocumentReference ): Promise { const firestore = cast(reference.firestore, Firestore); const mutations = [new DeleteMutation(reference._key, Precondition.none())]; @@ -394,10 +433,10 @@ export function deleteDoc( * newly created document after it has been written to the backend (Note that it * won't resolve while you're offline). */ -export function addDoc( - reference: CollectionReference, - data: WithFieldValue -): Promise> { +export function addDoc( + reference: CollectionReference, + data: WithFieldValue +): Promise> { const firestore = cast(reference.firestore, Firestore); const docRef = doc(reference); @@ -441,10 +480,10 @@ export interface Unsubscribe { * @returns An unsubscribe function that can be called to cancel * the snapshot listener. */ -export function onSnapshot( - reference: DocumentReference, +export function onSnapshot( + reference: DocumentReference, observer: { - next?: (snapshot: DocumentSnapshot) => void; + next?: (snapshot: DocumentSnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; } @@ -463,11 +502,11 @@ export function onSnapshot( * @returns An unsubscribe function that can be called to cancel * the snapshot listener. */ -export function onSnapshot( - reference: DocumentReference, +export function onSnapshot( + reference: DocumentReference, options: SnapshotListenOptions, observer: { - next?: (snapshot: DocumentSnapshot) => void; + next?: (snapshot: DocumentSnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; } @@ -490,9 +529,9 @@ export function onSnapshot( * @returns An unsubscribe function that can be called to cancel * the snapshot listener. */ -export function onSnapshot( - reference: DocumentReference, - onNext: (snapshot: DocumentSnapshot) => void, +export function onSnapshot( + reference: DocumentReference, + onNext: (snapshot: DocumentSnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void ): Unsubscribe; @@ -515,10 +554,10 @@ export function onSnapshot( * @returns An unsubscribe function that can be called to cancel * the snapshot listener. */ -export function onSnapshot( - reference: DocumentReference, +export function onSnapshot( + reference: DocumentReference, options: SnapshotListenOptions, - onNext: (snapshot: DocumentSnapshot) => void, + onNext: (snapshot: DocumentSnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void ): Unsubscribe; @@ -536,10 +575,10 @@ export function onSnapshot( * @returns An unsubscribe function that can be called to cancel * the snapshot listener. */ -export function onSnapshot( - query: Query, +export function onSnapshot( + query: Query, observer: { - next?: (snapshot: QuerySnapshot) => void; + next?: (snapshot: QuerySnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; } @@ -559,11 +598,11 @@ export function onSnapshot( * @returns An unsubscribe function that can be called to cancel * the snapshot listener. */ -export function onSnapshot( - query: Query, +export function onSnapshot( + query: Query, options: SnapshotListenOptions, observer: { - next?: (snapshot: QuerySnapshot) => void; + next?: (snapshot: QuerySnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; } @@ -587,9 +626,9 @@ export function onSnapshot( * @returns An unsubscribe function that can be called to cancel * the snapshot listener. */ -export function onSnapshot( - query: Query, - onNext: (snapshot: QuerySnapshot) => void, +export function onSnapshot( + query: Query, + onNext: (snapshot: QuerySnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void ): Unsubscribe; @@ -613,15 +652,17 @@ export function onSnapshot( * @returns An unsubscribe function that can be called to cancel * the snapshot listener. */ -export function onSnapshot( - query: Query, +export function onSnapshot( + query: Query, options: SnapshotListenOptions, - onNext: (snapshot: QuerySnapshot) => void, + onNext: (snapshot: QuerySnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void ): Unsubscribe; -export function onSnapshot( - reference: Query | DocumentReference, +export function onSnapshot( + reference: + | Query + | DocumentReference, ...args: unknown[] ): Unsubscribe { reference = getModularInstance(reference); @@ -640,7 +681,9 @@ export function onSnapshot( }; if (isPartialObserver(args[currArg])) { - const userObserver = args[currArg] as PartialObserver>; + const userObserver = args[currArg] as PartialObserver< + QuerySnapshot + >; args[currArg] = userObserver.next?.bind(userObserver); args[currArg + 1] = userObserver.error?.bind(userObserver); args[currArg + 2] = userObserver.complete?.bind(userObserver); @@ -657,10 +700,12 @@ export function onSnapshot( observer = { next: snapshot => { if (args[currArg]) { - (args[currArg] as NextFn>)( + ( + args[currArg] as NextFn> + )( convertToDocSnapshot( firestore, - reference as DocumentReference, + reference as DocumentReference, snapshot ) ); @@ -670,7 +715,7 @@ export function onSnapshot( complete: args[currArg + 2] as CompleteFn }; } else { - const query = cast>(reference, Query); + const query = cast>(reference, Query); firestore = cast(query.firestore, Firestore); internalQuery = query._query; const userDataWriter = new ExpUserDataWriter(firestore); @@ -678,7 +723,7 @@ export function onSnapshot( observer = { next: snapshot => { if (args[currArg]) { - (args[currArg] as NextFn>)( + (args[currArg] as NextFn>)( new QuerySnapshot(firestore, userDataWriter, query, snapshot) ); } @@ -776,11 +821,11 @@ export function executeWrite( * Converts a {@link ViewSnapshot} that contains the single document specified by `ref` * to a {@link DocumentSnapshot}. */ -function convertToDocSnapshot( +function convertToDocSnapshot( firestore: Firestore, - ref: DocumentReference, + ref: DocumentReference, snapshot: ViewSnapshot -): DocumentSnapshot { +): DocumentSnapshot { debugAssert( snapshot.docs.size <= 1, 'Expected zero or a single result on a document-only query' @@ -788,7 +833,7 @@ function convertToDocSnapshot( const doc = snapshot.docs.get(ref._key); const userDataWriter = new ExpUserDataWriter(firestore); - return new DocumentSnapshot( + return new DocumentSnapshot( firestore, userDataWriter, ref._key, diff --git a/packages/firestore/src/api/snapshot.ts b/packages/firestore/src/api/snapshot.ts index 658cb728da4..85671408f1d 100644 --- a/packages/firestore/src/api/snapshot.ts +++ b/packages/firestore/src/api/snapshot.ts @@ -83,8 +83,10 @@ import { SnapshotListenOptions } from './reference_impl'; * } * ``` */ -export interface FirestoreDataConverter - extends LiteFirestoreDataConverter { +export interface FirestoreDataConverter< + AppModelType, + DbModelType extends DocumentData = DocumentData +> extends LiteFirestoreDataConverter { /** * Called by the Firestore SDK to convert a custom model object of type `T` * into a plain JavaScript object (suitable for writing directly to the @@ -94,7 +96,9 @@ export interface FirestoreDataConverter * The `WithFieldValue` type extends `T` to also allow FieldValues such as * {@link (deleteField:1)} to be used as property values. */ - toFirestore(modelObject: WithFieldValue): DocumentData; + toFirestore( + modelObject: WithFieldValue + ): WithFieldValue; /** * Called by the Firestore SDK to convert a custom model object of type `T` @@ -108,9 +112,9 @@ export interface FirestoreDataConverter * omitted. */ toFirestore( - modelObject: PartialWithFieldValue, + modelObject: PartialWithFieldValue, options: SetOptions - ): DocumentData; + ): PartialWithFieldValue; /** * Called by the Firestore SDK to convert Firestore data into an object of @@ -120,9 +124,9 @@ export interface FirestoreDataConverter * @param options - The `SnapshotOptions` from the initial call to `data()`. */ fromFirestore( - snapshot: QueryDocumentSnapshot, + snapshot: QueryDocumentSnapshot, options?: SnapshotOptions - ): T; + ): AppModelType; } /** @@ -200,12 +204,15 @@ export type DocumentChangeType = 'added' | 'removed' | 'modified'; * A `DocumentChange` represents a change to the documents matching a query. * It contains the document affected and the type of change that occurred. */ -export interface DocumentChange { +export interface DocumentChange< + AppModelType = DocumentData, + DbModelType extends DocumentData = DocumentData +> { /** The type of change ('added', 'modified', or 'removed'). */ readonly type: DocumentChangeType; /** The document affected by this change. */ - readonly doc: QueryDocumentSnapshot; + readonly doc: QueryDocumentSnapshot; /** * The index of the changed document in the result set immediately prior to @@ -233,8 +240,9 @@ export interface DocumentChange { * explicitly verify a document's existence. */ export class DocumentSnapshot< - T = DocumentData -> extends LiteDocumentSnapshot { + AppModelType = DocumentData, + DbModelType extends DocumentData = DocumentData +> extends LiteDocumentSnapshot { private readonly _firestoreImpl: Firestore; /** @@ -250,7 +258,7 @@ export class DocumentSnapshot< key: DocumentKey, document: Document | null, metadata: SnapshotMetadata, - converter: UntypedFirestoreDataConverter | null + converter: UntypedFirestoreDataConverter | null ) { super(_firestore, userDataWriter, key, document, converter); this._firestoreImpl = _firestore; @@ -260,7 +268,7 @@ export class DocumentSnapshot< /** * Returns whether or not the data exists. True if the document exists. */ - exists(): this is QueryDocumentSnapshot { + exists(): this is QueryDocumentSnapshot { return super.exists(); } @@ -278,7 +286,7 @@ export class DocumentSnapshot< * @returns An `Object` containing all fields in the document or `undefined` if * the document doesn't exist. */ - data(options: SnapshotOptions = {}): T | undefined { + data(options: SnapshotOptions = {}): AppModelType | undefined { if (!this._document) { return undefined; } else if (this._converter) { @@ -297,7 +305,7 @@ export class DocumentSnapshot< return this._userDataWriter.convertValue( this._document.data.value, options.serverTimestamps - ) as T; + ) as AppModelType; } } @@ -347,8 +355,9 @@ export class DocumentSnapshot< * 'undefined'. */ export class QueryDocumentSnapshot< - T = DocumentData -> extends DocumentSnapshot { + AppModelType = DocumentData, + DbModelType extends DocumentData = DocumentData +> extends DocumentSnapshot { /** * Retrieves all fields in the document as an `Object`. * @@ -362,8 +371,8 @@ export class QueryDocumentSnapshot< * have not yet been set to their final value). * @returns An `Object` containing all fields in the document. */ - data(options: SnapshotOptions = {}): T { - return super.data(options) as T; + data(options: SnapshotOptions = {}): AppModelType { + return super.data(options) as AppModelType; } } @@ -374,7 +383,10 @@ export class QueryDocumentSnapshot< * number of documents can be determined via the `empty` and `size` * properties. */ -export class QuerySnapshot { +export class QuerySnapshot< + AppModelType = DocumentData, + DbModelType extends DocumentData = DocumentData +> { /** * Metadata about this snapshot, concerning its source and if it has local * modifications. @@ -385,16 +397,16 @@ export class QuerySnapshot { * The query on which you called `get` or `onSnapshot` in order to get this * `QuerySnapshot`. */ - readonly query: Query; + readonly query: Query; - private _cachedChanges?: Array>; + private _cachedChanges?: Array>; private _cachedChangesIncludeMetadataChanges?: boolean; /** @hideconstructor */ constructor( readonly _firestore: Firestore, readonly _userDataWriter: AbstractUserDataWriter, - query: Query, + query: Query, readonly _snapshot: ViewSnapshot ) { this.metadata = new SnapshotMetadata( @@ -405,8 +417,8 @@ export class QuerySnapshot { } /** An array of all the documents in the `QuerySnapshot`. */ - get docs(): Array> { - const result: Array> = []; + get docs(): Array> { + const result: Array> = []; this.forEach(doc => result.push(doc)); return result; } @@ -429,13 +441,15 @@ export class QuerySnapshot { * @param thisArg - The `this` binding for the callback. */ forEach( - callback: (result: QueryDocumentSnapshot) => void, + callback: ( + result: QueryDocumentSnapshot + ) => void, thisArg?: unknown ): void { this._snapshot.docs.forEach(doc => { callback.call( thisArg, - new QueryDocumentSnapshot( + new QueryDocumentSnapshot( this._firestore, this._userDataWriter, doc.key, @@ -459,7 +473,9 @@ export class QuerySnapshot { * changes (i.e. only `DocumentSnapshot.metadata` changed) should trigger * snapshot events. */ - docChanges(options: SnapshotListenOptions = {}): Array> { + docChanges( + options: SnapshotListenOptions = {} + ): Array> { const includeMetadataChanges = !!options.includeMetadataChanges; if (includeMetadataChanges && this._snapshot.excludesMetadataChanges) { @@ -483,10 +499,13 @@ export class QuerySnapshot { } /** Calculates the array of `DocumentChange`s for a given `ViewSnapshot`. */ -export function changesFromSnapshot( - querySnapshot: QuerySnapshot, +export function changesFromSnapshot< + AppModelType, + DbModelType extends DocumentData +>( + querySnapshot: QuerySnapshot, includeMetadataChanges: boolean -): Array> { +): Array> { if (querySnapshot._snapshot.oldDocs.isEmpty()) { // Special case the first snapshot because index calculation is easy and // fast @@ -505,7 +524,7 @@ export function changesFromSnapshot( ) < 0, 'Got added events in wrong order' ); - const doc = new QueryDocumentSnapshot( + const doc = new QueryDocumentSnapshot( querySnapshot._firestore, querySnapshot._userDataWriter, change.doc.key, @@ -533,7 +552,7 @@ export function changesFromSnapshot( change => includeMetadataChanges || change.type !== ChangeType.Metadata ) .map(change => { - const doc = new QueryDocumentSnapshot( + const doc = new QueryDocumentSnapshot( querySnapshot._firestore, querySnapshot._userDataWriter, change.doc.key, @@ -588,9 +607,13 @@ export function resultChangeType(type: ChangeType): DocumentChangeType { * @param right - A snapshot to compare. * @returns true if the snapshots are equal. */ -export function snapshotEqual( - left: DocumentSnapshot | QuerySnapshot, - right: DocumentSnapshot | QuerySnapshot +export function snapshotEqual( + left: + | DocumentSnapshot + | QuerySnapshot, + right: + | DocumentSnapshot + | QuerySnapshot ): boolean { if (left instanceof DocumentSnapshot && right instanceof DocumentSnapshot) { return ( diff --git a/packages/firestore/src/api/transaction.ts b/packages/firestore/src/api/transaction.ts index a70cfba231d..a1deab9e295 100644 --- a/packages/firestore/src/api/transaction.ts +++ b/packages/firestore/src/api/transaction.ts @@ -22,7 +22,7 @@ import { DEFAULT_TRANSACTION_OPTIONS, validateTransactionOptions } from '../core/transaction_options'; -import { DocumentReference } from '../lite-api/reference'; +import { DocumentData, DocumentReference } from '../lite-api/reference'; import { Transaction as LiteTransaction } from '../lite-api/transaction'; import { validateReference } from '../lite-api/write_batch'; import { cast } from '../util/input_validation'; @@ -57,8 +57,10 @@ export class Transaction extends LiteTransaction { * @param documentRef - A reference to the document to be read. * @returns A `DocumentSnapshot` with the read data. */ - get(documentRef: DocumentReference): Promise> { - const ref = validateReference(documentRef, this._firestore); + get( + documentRef: DocumentReference + ): Promise> { + const ref = validateReference(documentRef, this._firestore); const userDataWriter = new ExpUserDataWriter(this._firestore); return super .get(documentRef) diff --git a/packages/firestore/src/core/firestore_client.ts b/packages/firestore/src/core/firestore_client.ts index df6127f978e..595cdb0ca01 100644 --- a/packages/firestore/src/core/firestore_client.ts +++ b/packages/firestore/src/core/firestore_client.ts @@ -91,6 +91,8 @@ import { TransactionOptions } from './transaction_options'; import { TransactionRunner } from './transaction_runner'; import { View } from './view'; import { ViewSnapshot } from './view_snapshot'; +import { AggregateSpec } from '../lite-api/aggregate_types'; +import { DocumentData } from '../lite-api/reference'; const LOG_TAG = 'FirestoreClient'; export const MAX_CONCURRENT_LIMBO_RESOLUTIONS = 100; diff --git a/packages/firestore/src/lite-api/aggregate.ts b/packages/firestore/src/lite-api/aggregate.ts index 33e8012245e..20cf8805c23 100644 --- a/packages/firestore/src/lite-api/aggregate.ts +++ b/packages/firestore/src/lite-api/aggregate.ts @@ -31,7 +31,7 @@ import { import { getDatastore } from './components'; import { Firestore } from './database'; import { FieldPath } from './field_path'; -import { Query, queryEqual } from './reference'; +import { DocumentData, Query, queryEqual } from './reference'; import { LiteUserDataWriter } from './reference_impl'; import { fieldPathFromArgument } from './user_data_reader'; @@ -49,9 +49,15 @@ import { fieldPathFromArgument } from './user_data_reader'; * retrieved from `snapshot.data().count`, where `snapshot` is the * `AggregateQuerySnapshot` to which the returned Promise resolves. */ -export function getCount( - query: Query -): Promise }>> { +export function getCount( + query: Query +): Promise< + AggregateQuerySnapshot< + { count: AggregateField }, + AppModelType, + DbModelType + > +> { const countQuerySpec: { count: AggregateField } = { count: count() }; @@ -86,10 +92,16 @@ export function getCount( * ``` * @internal TODO (sum/avg) remove when public */ -export function getAggregate( - query: Query, - aggregateSpec: T -): Promise> { +export function getAggregate< + AggregateSpecType extends AggregateSpec, + AppModelType, + DbModelType extends DocumentData +>( + query: Query, + aggregateSpec: AggregateSpecType +): Promise< + AggregateQuerySnapshot +> { const firestore = cast(query.firestore, Firestore); const datastore = getDatastore(firestore); @@ -111,17 +123,21 @@ export function getAggregate( ); } -function convertToAggregateQuerySnapshot( +function convertToAggregateQuerySnapshot< + AggregateSpecType extends AggregateSpec, + AppModelType, + DbModelType extends DocumentData +>( firestore: Firestore, - query: Query, + query: Query, aggregateResult: ApiClientObjectMap -): AggregateQuerySnapshot { +): AggregateQuerySnapshot { const userDataWriter = new LiteUserDataWriter(firestore); - const querySnapshot = new AggregateQuerySnapshot( - query, - userDataWriter, - aggregateResult - ); + const querySnapshot = new AggregateQuerySnapshot< + AggregateSpecType, + AppModelType, + DbModelType + >(query, userDataWriter, aggregateResult); return querySnapshot; } @@ -188,9 +204,13 @@ export function aggregateFieldEqual( * @returns `true` if the objects are "equal", as defined above, or `false` * otherwise. */ -export function aggregateQuerySnapshotEqual( - left: AggregateQuerySnapshot, - right: AggregateQuerySnapshot +export function aggregateQuerySnapshotEqual< + AggregateSpecType extends AggregateSpec, + AppModelType, + DbModelType extends DocumentData +>( + left: AggregateQuerySnapshot, + right: AggregateQuerySnapshot ): boolean { return ( queryEqual(left.query, right.query) && deepEqual(left.data(), right.data()) diff --git a/packages/firestore/src/lite-api/aggregate_types.ts b/packages/firestore/src/lite-api/aggregate_types.ts index 9223b783138..8546057cc09 100644 --- a/packages/firestore/src/lite-api/aggregate_types.ts +++ b/packages/firestore/src/lite-api/aggregate_types.ts @@ -19,7 +19,7 @@ import { AggregateType } from '../core/aggregate'; import { FieldPath as InternalFieldPath } from '../model/path'; import { ApiClientObjectMap, Value } from '../protos/firestore_proto_api'; -import { Query } from './reference'; +import { DocumentData, Query } from './reference'; import { AbstractUserDataWriter } from './user_data_writer'; export { AggregateType }; @@ -71,7 +71,11 @@ export type AggregateSpecData = { /** * The results of executing an aggregation query. */ -export class AggregateQuerySnapshot { +export class AggregateQuerySnapshot< + AggregateSpecType extends AggregateSpec, + AppModelType = DocumentData, + DbModelType extends DocumentData = DocumentData +> { /** A type string to uniquely identify instances of this class. */ readonly type = 'AggregateQuerySnapshot'; @@ -79,11 +83,11 @@ export class AggregateQuerySnapshot { * The underlying query over which the aggregations recorded in this * `AggregateQuerySnapshot` were performed. */ - readonly query: Query; + readonly query: Query; /** @hideconstructor */ constructor( - query: Query, + query: Query, private readonly _userDataWriter: AbstractUserDataWriter, private readonly _data: ApiClientObjectMap ) { @@ -101,9 +105,9 @@ export class AggregateQuerySnapshot { * @returns The results of the aggregations performed over the underlying * query. */ - data(): AggregateSpecData { + data(): AggregateSpecData { return this._userDataWriter.convertObjectMap( this._data - ) as AggregateSpecData; + ) as AggregateSpecData; } } diff --git a/packages/firestore/src/lite-api/query.ts b/packages/firestore/src/lite-api/query.ts index 3afa282048f..cff35769845 100644 --- a/packages/firestore/src/lite-api/query.ts +++ b/packages/firestore/src/lite-api/query.ts @@ -53,7 +53,7 @@ import { } from '../util/input_validation'; import { FieldPath } from './field_path'; -import { DocumentReference, Query } from './reference'; +import { DocumentData, DocumentReference, Query } from './reference'; import { DocumentSnapshot, fieldPathFromArgument } from './snapshot'; import { newUserDataReader, @@ -95,7 +95,9 @@ export abstract class AppliableConstraint { * Takes the provided {@link Query} and returns a copy of the {@link Query} with this * {@link AppliableConstraint} applied. */ - abstract _apply(query: Query): Query; + abstract _apply( + query: Query + ): Query; } /** @@ -114,7 +116,9 @@ export abstract class QueryConstraint extends AppliableConstraint { * Takes the provided {@link Query} and returns a copy of the {@link Query} with this * {@link AppliableConstraint} applied. */ - abstract _apply(query: Query): Query; + abstract _apply( + query: Query + ): Query; } /** @@ -131,11 +135,11 @@ export abstract class QueryConstraint extends AppliableConstraint { * @throws if any of the provided query constraints cannot be combined with the * existing or new constraints. */ -export function query( - query: Query, +export function query( + query: Query, compositeFilter: QueryCompositeFilterConstraint, ...queryConstraints: QueryNonFilterConstraint[] -): Query; +): Query; /** * Creates a new immutable instance of {@link Query} that is extended to also @@ -147,18 +151,18 @@ export function query( * @throws if any of the provided query constraints cannot be combined with the * existing or new constraints. */ -export function query( - query: Query, +export function query( + query: Query, ...queryConstraints: QueryConstraint[] -): Query; +): Query; -export function query( - query: Query, +export function query( + query: Query, queryConstraint: QueryCompositeFilterConstraint | QueryConstraint | undefined, ...additionalQueryConstraints: Array< QueryConstraint | QueryNonFilterConstraint > -): Query { +): Query { let queryConstraints: AppliableConstraint[] = []; if (queryConstraint instanceof AppliableConstraint) { @@ -205,7 +209,9 @@ export class QueryFieldFilterConstraint extends QueryConstraint { return new QueryFieldFilterConstraint(_field, _op, _value); } - _apply(query: Query): Query { + _apply( + query: Query + ): Query { const filter = this._parse(query); validateNewFieldFilter(query._query, filter); return new Query( @@ -215,7 +221,9 @@ export class QueryFieldFilterConstraint extends QueryConstraint { ); } - _parse(query: Query): FieldFilter { + _parse( + query: Query + ): FieldFilter { const reader = newUserDataReader(query.firestore); const filter = newQueryFilter( query._query, @@ -295,7 +303,9 @@ export class QueryCompositeFilterConstraint extends AppliableConstraint { return new QueryCompositeFilterConstraint(type, _queryConstraints); } - _parse(query: Query): Filter { + _parse( + query: Query + ): Filter { const parsedFilters = this._queryConstraints .map(queryConstraint => { return queryConstraint._parse(query); @@ -309,7 +319,9 @@ export class QueryCompositeFilterConstraint extends AppliableConstraint { return CompositeFilter.create(parsedFilters, this._getOperator()); } - _apply(query: Query): Query { + _apply( + query: Query + ): Query { const parsedFilter = this._parse(query); if (parsedFilter.getFilters().length === 0) { // Return the existing query if not adding any more filters (e.g. an empty @@ -435,7 +447,9 @@ export class QueryOrderByConstraint extends QueryConstraint { return new QueryOrderByConstraint(_field, _direction); } - _apply(query: Query): Query { + _apply( + query: Query + ): Query { const orderBy = newQueryOrderBy(query._query, this._field, this._direction); return new Query( query.firestore, @@ -500,7 +514,9 @@ export class QueryLimitConstraint extends QueryConstraint { return new QueryLimitConstraint(type, _limit, _limitType); } - _apply(query: Query): Query { + _apply( + query: Query + ): Query { return new Query( query.firestore, query.converter, @@ -564,14 +580,16 @@ export class QueryStartAtConstraint extends QueryConstraint { return new QueryStartAtConstraint(type, _docOrFields, _inclusive); } - _apply(query: Query): Query { + _apply( + query: Query + ): Query { const bound = newQueryBoundFromDocOrFields( query, this.type, this._docOrFields, this._inclusive ); - return new Query( + return new Query( query.firestore, query.converter, queryWithStartAt(query._query, bound) @@ -671,7 +689,9 @@ export class QueryEndAtConstraint extends QueryConstraint { return new QueryEndAtConstraint(type, _docOrFields, _inclusive); } - _apply(query: Query): Query { + _apply( + query: Query + ): Query { const bound = newQueryBoundFromDocOrFields( query, this.type, @@ -751,10 +771,13 @@ export function endAt( } /** Helper function to create a bound from a document or fields */ -function newQueryBoundFromDocOrFields( - query: Query, +function newQueryBoundFromDocOrFields< + AppModelType, + DbModelType extends DocumentData +>( + query: Query, methodName: string, - docOrFields: Array>, + docOrFields: Array>, inclusive: boolean ): Bound { docOrFields[0] = getModularInstance(docOrFields[0]); diff --git a/packages/firestore/src/lite-api/reference.ts b/packages/firestore/src/lite-api/reference.ts index 0a9fdcf71cd..466e22caf39 100644 --- a/packages/firestore/src/lite-api/reference.ts +++ b/packages/firestore/src/lite-api/reference.ts @@ -108,12 +108,79 @@ export type SetOptions = readonly mergeFields?: Array; }; +/** + * A `Query` refers to a query which you can read or listen to. You can also + * construct refined `Query` objects by adding filters and ordering. + */ +export class Query< + AppModelType = DocumentData, + DbModelType extends DocumentData = DocumentData +> { + /** The type of this Firestore reference. */ + readonly type: 'query' | 'collection' = 'query'; + + /** + * The `Firestore` instance for the Firestore database (useful for performing + * transactions, etc.). + */ + readonly firestore: Firestore; + + // This is the lite version of the Query class in the main SDK. + + /** @hideconstructor protected */ + constructor( + firestore: Firestore, + /** + * If provided, the `FirestoreDataConverter` associated with this instance. + */ + readonly converter: FirestoreDataConverter< + AppModelType, + DbModelType + > | null, + readonly _query: InternalQuery + ) { + this.firestore = firestore; + } + + /** + * Removes the current converter. + * + * @param converter - `null` removes the current converter. + * @returns A `Query` that does not use a converter. + */ + withConverter(converter: null): Query; + /** + * Applies a custom data converter to this query, allowing you to use your own + * custom model objects with Firestore. When you call {@link getDocs} with + * the returned query, the provided converter will convert between Firestore + * data and your custom type `U`. + * + * @param converter - Converts objects to and from Firestore. + * @returns A `Query` that uses the provided converter. + */ + withConverter( + converter: FirestoreDataConverter + ): Query; + withConverter( + converter: FirestoreDataConverter | null + ): Query { + return new Query( + this.firestore, + converter, + this._query + ); + } +} + /** * A `DocumentReference` refers to a document location in a Firestore database * and can be used to write, read, or listen to the location. The document at * the referenced location may or may not exist. */ -export class DocumentReference { +export class DocumentReference< + AppModelType = DocumentData, + DbModelType extends DocumentData = DocumentData +> { /** The type of this Firestore reference. */ readonly type = 'document'; @@ -129,7 +196,10 @@ export class DocumentReference { /** * If provided, the `FirestoreDataConverter` associated with this instance. */ - readonly converter: FirestoreDataConverter | null, + readonly converter: FirestoreDataConverter< + AppModelType, + DbModelType + > | null, readonly _key: DocumentKey ) { this.firestore = firestore; @@ -157,8 +227,8 @@ export class DocumentReference { /** * The collection this `DocumentReference` belongs to. */ - get parent(): CollectionReference { - return new CollectionReference( + get parent(): CollectionReference { + return new CollectionReference( this.firestore, this.converter, this._key.path.popLast() @@ -175,68 +245,24 @@ export class DocumentReference { * @param converter - Converts objects to and from Firestore. * @returns A `DocumentReference` that uses the provided converter. */ - withConverter(converter: FirestoreDataConverter): DocumentReference; + withConverter( + converter: FirestoreDataConverter + ): DocumentReference; /** * Removes the current converter. * * @param converter - `null` removes the current converter. * @returns A `DocumentReference` that does not use a converter. */ - withConverter(converter: null): DocumentReference; - withConverter( - converter: FirestoreDataConverter | null - ): DocumentReference { - return new DocumentReference(this.firestore, converter, this._key); - } -} - -/** - * A `Query` refers to a query which you can read or listen to. You can also - * construct refined `Query` objects by adding filters and ordering. - */ -export class Query { - /** The type of this Firestore reference. */ - readonly type: 'query' | 'collection' = 'query'; - - /** - * The `Firestore` instance for the Firestore database (useful for performing - * transactions, etc.). - */ - readonly firestore: Firestore; - - // This is the lite version of the Query class in the main SDK. - - /** @hideconstructor protected */ - constructor( - firestore: Firestore, - /** - * If provided, the `FirestoreDataConverter` associated with this instance. - */ - readonly converter: FirestoreDataConverter | null, - readonly _query: InternalQuery - ) { - this.firestore = firestore; - } - - /** - * Removes the current converter. - * - * @param converter - `null` removes the current converter. - * @returns A `Query` that does not use a converter. - */ - withConverter(converter: null): Query; - /** - * Applies a custom data converter to this query, allowing you to use your own - * custom model objects with Firestore. When you call {@link getDocs} with - * the returned query, the provided converter will convert between Firestore - * data and your custom type `U`. - * - * @param converter - Converts objects to and from Firestore. - * @returns A `Query` that uses the provided converter. - */ - withConverter(converter: FirestoreDataConverter): Query; - withConverter(converter: FirestoreDataConverter | null): Query { - return new Query(this.firestore, converter, this._query); + withConverter(converter: null): DocumentReference; + withConverter( + converter: FirestoreDataConverter | null + ): DocumentReference { + return new DocumentReference( + this.firestore, + converter, + this._key + ); } } @@ -244,14 +270,17 @@ export class Query { * A `CollectionReference` object can be used for adding documents, getting * document references, and querying for documents (using {@link (query:1)}). */ -export class CollectionReference extends Query { +export class CollectionReference< + AppModelType = DocumentData, + DbModelType extends DocumentData = DocumentData +> extends Query { /** The type of this Firestore reference. */ readonly type = 'collection'; /** @hideconstructor */ constructor( firestore: Firestore, - converter: FirestoreDataConverter | null, + converter: FirestoreDataConverter | null, readonly _path: ResourcePath ) { super(firestore, converter, newQueryForPath(_path)); @@ -274,7 +303,7 @@ export class CollectionReference extends Query { * A reference to the containing `DocumentReference` if this is a * subcollection. If this isn't a subcollection, the reference is null. */ - get parent(): DocumentReference | null { + get parent(): DocumentReference | null { const parentPath = this._path.popLast(); if (parentPath.isEmpty()) { return null; @@ -296,9 +325,9 @@ export class CollectionReference extends Query { * @param converter - Converts objects to and from Firestore. * @returns A `CollectionReference` that uses the provided converter. */ - withConverter( - converter: FirestoreDataConverter - ): CollectionReference; + withConverter( + converter: FirestoreDataConverter + ): CollectionReference; /** * Removes the current converter. * @@ -306,11 +335,17 @@ export class CollectionReference extends Query { * @returns A `CollectionReference` that does not use a * converter. */ - withConverter(converter: null): CollectionReference; - withConverter( - converter: FirestoreDataConverter | null - ): CollectionReference { - return new CollectionReference(this.firestore, converter, this._path); + withConverter( + converter: null + ): CollectionReference; + withConverter( + converter: FirestoreDataConverter | null + ): CollectionReference { + return new CollectionReference( + this.firestore, + converter, + this._path + ); } } @@ -330,7 +365,7 @@ export function collection( firestore: Firestore, path: string, ...pathSegments: string[] -): CollectionReference; +): CollectionReference; /** * Gets a `CollectionReference` instance that refers to a subcollection of * `reference` at the the specified relative path. @@ -343,11 +378,11 @@ export function collection( * to a collection. * @returns The `CollectionReference` instance. */ -export function collection( - reference: CollectionReference, +export function collection( + reference: CollectionReference, path: string, ...pathSegments: string[] -): CollectionReference; +): CollectionReference; /** * Gets a `CollectionReference` instance that refers to a subcollection of * `reference` at the the specified relative path. @@ -360,16 +395,19 @@ export function collection( * to a collection. * @returns The `CollectionReference` instance. */ -export function collection( - reference: DocumentReference, +export function collection( + reference: DocumentReference, path: string, ...pathSegments: string[] -): CollectionReference; -export function collection( - parent: Firestore | DocumentReference | CollectionReference, +): CollectionReference; +export function collection( + parent: + | Firestore + | DocumentReference + | CollectionReference, path: string, ...pathSegments: string[] -): CollectionReference { +): CollectionReference { parent = getModularInstance(parent); validateNonEmptyArgument('collection', 'path', path); @@ -417,7 +455,7 @@ export function collection( export function collectionGroup( firestore: Firestore, collectionId: string -): Query { +): Query { firestore = cast(firestore, Firestore); validateNonEmptyArgument('collectionGroup', 'collection id', collectionId); @@ -452,7 +490,7 @@ export function doc( firestore: Firestore, path: string, ...pathSegments: string[] -): DocumentReference; +): DocumentReference; /** * Gets a `DocumentReference` instance that refers to a document within * `reference` at the specified relative path. If no path is specified, an @@ -468,11 +506,11 @@ export function doc( * a document. * @returns The `DocumentReference` instance. */ -export function doc( - reference: CollectionReference, +export function doc( + reference: CollectionReference, path?: string, ...pathSegments: string[] -): DocumentReference; +): DocumentReference; /** * Gets a `DocumentReference` instance that refers to a document within * `reference` at the specified relative path. @@ -485,16 +523,19 @@ export function doc( * a document. * @returns The `DocumentReference` instance. */ -export function doc( - reference: DocumentReference, +export function doc( + reference: DocumentReference, path: string, ...pathSegments: string[] -): DocumentReference; -export function doc( - parent: Firestore | CollectionReference | DocumentReference, +): DocumentReference; +export function doc( + parent: + | Firestore + | CollectionReference + | DocumentReference, path?: string, ...pathSegments: string[] -): DocumentReference { +): DocumentReference { parent = getModularInstance(parent); // We allow omission of 'pathString' but explicitly prohibit passing in both @@ -527,7 +568,7 @@ export function doc( ResourcePath.fromString(path, ...pathSegments) ); validateDocumentPath(absolutePath); - return new DocumentReference( + return new DocumentReference( parent.firestore, parent instanceof CollectionReference ? parent.converter : null, new DocumentKey(absolutePath) @@ -543,9 +584,13 @@ export function doc( * @returns true if the references point to the same location in the same * Firestore database. */ -export function refEqual( - left: DocumentReference | CollectionReference, - right: DocumentReference | CollectionReference +export function refEqual( + left: + | DocumentReference + | CollectionReference, + right: + | DocumentReference + | CollectionReference ): boolean { left = getModularInstance(left); right = getModularInstance(right); @@ -573,7 +618,10 @@ export function refEqual( * @returns true if the references point to the same location in the same * Firestore database. */ -export function queryEqual(left: Query, right: Query): boolean { +export function queryEqual( + left: Query, + right: Query +): boolean { left = getModularInstance(left); right = getModularInstance(right); diff --git a/packages/firestore/src/lite-api/reference_impl.ts b/packages/firestore/src/lite-api/reference_impl.ts index e478cc76eb4..cc815edc200 100644 --- a/packages/firestore/src/lite-api/reference_impl.ts +++ b/packages/firestore/src/lite-api/reference_impl.ts @@ -40,6 +40,7 @@ import { validateHasExplicitOrderByForLimitToLast } from './query'; import { CollectionReference, doc, + DocumentData, DocumentReference, PartialWithFieldValue, Query, @@ -120,10 +121,13 @@ export class LiteUserDataWriter extends AbstractUserDataWriter { * @returns A Promise resolved with a `DocumentSnapshot` containing the current * document contents. */ -export function getDoc( - reference: DocumentReference -): Promise> { - reference = cast>(reference, DocumentReference); +export function getDoc( + reference: DocumentReference +): Promise> { + reference = cast>( + reference, + DocumentReference + ); const datastore = getDatastore(reference.firestore); const userDataWriter = new LiteUserDataWriter(reference.firestore); @@ -131,7 +135,7 @@ export function getDoc( result => { hardAssert(result.length === 1, 'Expected a single document result'); const document = result[0]; - return new DocumentSnapshot( + return new DocumentSnapshot( reference.firestore, userDataWriter, reference._key, @@ -154,8 +158,10 @@ export function getDoc( * @param query - The `Query` to execute. * @returns A Promise that will be resolved with the results of the query. */ -export function getDocs(query: Query): Promise> { - query = cast>(query, Query); +export function getDocs( + query: Query +): Promise> { + query = cast>(query, Query); validateHasExplicitOrderByForLimitToLast(query._query); const datastore = getDatastore(query.firestore); @@ -163,7 +169,7 @@ export function getDocs(query: Query): Promise> { return invokeRunQueryRpc(datastore, query._query).then(result => { const docs = result.map( doc => - new QueryDocumentSnapshot( + new QueryDocumentSnapshot( query.firestore, userDataWriter, doc.key, @@ -179,7 +185,7 @@ export function getDocs(query: Query): Promise> { docs.reverse(); } - return new QuerySnapshot(query, docs); + return new QuerySnapshot(query, docs); }); } @@ -198,9 +204,9 @@ export function getDocs(query: Query): Promise> { * @returns A `Promise` resolved once the data has been successfully written * to the backend. */ -export function setDoc( - reference: DocumentReference, - data: WithFieldValue +export function setDoc( + reference: DocumentReference, + data: WithFieldValue ): Promise; /** * Writes to the document referred to by the specified `DocumentReference`. If @@ -219,17 +225,20 @@ export function setDoc( * @returns A `Promise` resolved once the data has been successfully written * to the backend. */ -export function setDoc( - reference: DocumentReference, - data: PartialWithFieldValue, +export function setDoc( + reference: DocumentReference, + data: PartialWithFieldValue, options: SetOptions ): Promise; -export function setDoc( - reference: DocumentReference, - data: PartialWithFieldValue, +export function setDoc( + reference: DocumentReference, + data: PartialWithFieldValue, options?: SetOptions ): Promise { - reference = cast>(reference, DocumentReference); + reference = cast>( + reference, + DocumentReference + ); const convertedValue = applyFirestoreDataConverter( reference.converter, data, @@ -269,9 +278,9 @@ export function setDoc( * @returns A `Promise` resolved once the data has been successfully written * to the backend. */ -export function updateDoc( - reference: DocumentReference, - data: UpdateData +export function updateDoc( + reference: DocumentReference, + data: UpdateData ): Promise; /** * Updates fields in the document referred to by the specified @@ -294,19 +303,22 @@ export function updateDoc( * @returns A `Promise` resolved once the data has been successfully written * to the backend. */ -export function updateDoc( - reference: DocumentReference, +export function updateDoc( + reference: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[] ): Promise; -export function updateDoc( - reference: DocumentReference, - fieldOrUpdateData: string | FieldPath | UpdateData, +export function updateDoc( + reference: DocumentReference, + fieldOrUpdateData: string | FieldPath | UpdateData, value?: unknown, ...moreFieldsAndValues: unknown[] ): Promise { - reference = cast>(reference, DocumentReference); + reference = cast>( + reference, + DocumentReference + ); const dataReader = newUserDataReader(reference.firestore); // For Compat types, we have to "extract" the underlying types before @@ -353,10 +365,13 @@ export function updateDoc( * @returns A `Promise` resolved once the document has been successfully * deleted from the backend. */ -export function deleteDoc( - reference: DocumentReference +export function deleteDoc( + reference: DocumentReference ): Promise { - reference = cast>(reference, DocumentReference); + reference = cast>( + reference, + DocumentReference + ); const datastore = getDatastore(reference.firestore); return invokeCommitRpc(datastore, [ new DeleteMutation(reference._key, Precondition.none()) @@ -378,16 +393,19 @@ export function deleteDoc( * @returns A `Promise` resolved with a `DocumentReference` pointing to the * newly created document after it has been written to the backend. */ -export function addDoc( - reference: CollectionReference, - data: WithFieldValue -): Promise> { - reference = cast>(reference, CollectionReference); +export function addDoc( + reference: CollectionReference, + data: WithFieldValue +): Promise> { + reference = cast>( + reference, + CollectionReference + ); const docRef = doc(reference); const convertedValue = applyFirestoreDataConverter( reference.converter, - data as PartialWithFieldValue + data as PartialWithFieldValue ); const dataReader = newUserDataReader(reference.firestore); diff --git a/packages/firestore/src/lite-api/snapshot.ts b/packages/firestore/src/lite-api/snapshot.ts index d726d92a7e4..9c268eeb52c 100644 --- a/packages/firestore/src/lite-api/snapshot.ts +++ b/packages/firestore/src/lite-api/snapshot.ts @@ -78,7 +78,10 @@ import { AbstractUserDataWriter } from './user_data_writer'; * } * ``` */ -export interface FirestoreDataConverter { +export interface FirestoreDataConverter< + AppModelType, + DbModelType extends DocumentData = DocumentData +> { /** * Called by the Firestore SDK to convert a custom model object of type `T` * into a plain Javascript object (suitable for writing directly to the @@ -88,7 +91,9 @@ export interface FirestoreDataConverter { * The `WithFieldValue` type extends `T` to also allow FieldValues such as * {@link (deleteField:1)} to be used as property values. */ - toFirestore(modelObject: WithFieldValue): DocumentData; + toFirestore( + modelObject: WithFieldValue + ): WithFieldValue; /** * Called by the Firestore SDK to convert a custom model object of type `T` @@ -102,9 +107,9 @@ export interface FirestoreDataConverter { * omitted. */ toFirestore( - modelObject: PartialWithFieldValue, + modelObject: PartialWithFieldValue, options: SetOptions - ): DocumentData; + ): PartialWithFieldValue; /** * Called by the Firestore SDK to convert Firestore data into an object of @@ -113,7 +118,9 @@ export interface FirestoreDataConverter { * @param snapshot - A `QueryDocumentSnapshot` containing your data and * metadata. */ - fromFirestore(snapshot: QueryDocumentSnapshot): T; + fromFirestore( + snapshot: QueryDocumentSnapshot + ): AppModelType; } /** @@ -125,7 +132,10 @@ export interface FirestoreDataConverter { * access will return 'undefined'. You can use the `exists()` method to * explicitly verify a document's existence. */ -export class DocumentSnapshot { +export class DocumentSnapshot< + AppModelType = DocumentData, + DbModelType extends DocumentData = DocumentData +> { // Note: This class is stripped down version of the DocumentSnapshot in // the legacy SDK. The changes are: // - No support for SnapshotMetadata. @@ -137,7 +147,10 @@ export class DocumentSnapshot { public _userDataWriter: AbstractUserDataWriter, public _key: DocumentKey, public _document: Document | null, - public _converter: UntypedFirestoreDataConverter | null + public _converter: UntypedFirestoreDataConverter< + AppModelType, + DbModelType + > | null ) {} /** Property of the `DocumentSnapshot` that provides the document's ID. */ @@ -148,8 +161,8 @@ export class DocumentSnapshot { /** * The `DocumentReference` for the document included in the `DocumentSnapshot`. */ - get ref(): DocumentReference { - return new DocumentReference( + get ref(): DocumentReference { + return new DocumentReference( this._firestore, this._converter, this._key @@ -161,7 +174,7 @@ export class DocumentSnapshot { * * @returns true if the document exists. */ - exists(): this is QueryDocumentSnapshot { + exists(): this is QueryDocumentSnapshot { return this._document !== null; } @@ -172,7 +185,7 @@ export class DocumentSnapshot { * @returns An `Object` containing all fields in the document or `undefined` * if the document doesn't exist. */ - data(): T | undefined { + data(): AppModelType | undefined { if (!this._document) { return undefined; } else if (this._converter) { @@ -187,7 +200,9 @@ export class DocumentSnapshot { ); return this._converter.fromFirestore(snapshot); } else { - return this._userDataWriter.convertValue(this._document.data.value) as T; + return this._userDataWriter.convertValue( + this._document.data.value + ) as AppModelType; } } @@ -227,16 +242,17 @@ export class DocumentSnapshot { * 'undefined'. */ export class QueryDocumentSnapshot< - T = DocumentData -> extends DocumentSnapshot { + AppModelType = DocumentData, + DbModelType extends DocumentData = DocumentData +> extends DocumentSnapshot { /** * Retrieves all fields in the document as an `Object`. * * @override * @returns An `Object` containing all fields in the document. */ - data(): T { - return super.data() as T; + data(): AppModelType { + return super.data() as AppModelType; } } @@ -247,23 +263,26 @@ export class QueryDocumentSnapshot< * number of documents can be determined via the `empty` and `size` * properties. */ -export class QuerySnapshot { +export class QuerySnapshot< + AppModelType = DocumentData, + DbModelType extends DocumentData = DocumentData +> { /** * The query on which you called {@link getDocs} in order to get this * `QuerySnapshot`. */ - readonly query: Query; + readonly query: Query; /** @hideconstructor */ constructor( - _query: Query, - readonly _docs: Array> + _query: Query, + readonly _docs: Array> ) { this.query = _query; } /** An array of all the documents in the `QuerySnapshot`. */ - get docs(): Array> { + get docs(): Array> { return [...this._docs]; } @@ -285,7 +304,9 @@ export class QuerySnapshot { * @param thisArg - The `this` binding for the callback. */ forEach( - callback: (result: QueryDocumentSnapshot) => void, + callback: ( + result: QueryDocumentSnapshot + ) => void, thisArg?: unknown ): void { this._docs.forEach(callback, thisArg); @@ -299,9 +320,13 @@ export class QuerySnapshot { * @param right - A snapshot to compare. * @returns true if the snapshots are equal. */ -export function snapshotEqual( - left: DocumentSnapshot | QuerySnapshot, - right: DocumentSnapshot | QuerySnapshot +export function snapshotEqual( + left: + | DocumentSnapshot + | QuerySnapshot, + right: + | DocumentSnapshot + | QuerySnapshot ): boolean { left = getModularInstance(left); right = getModularInstance(right); diff --git a/packages/firestore/src/lite-api/transaction.ts b/packages/firestore/src/lite-api/transaction.ts index aab718cf91d..40bb70460e8 100644 --- a/packages/firestore/src/lite-api/transaction.ts +++ b/packages/firestore/src/lite-api/transaction.ts @@ -33,6 +33,7 @@ import { getDatastore } from './components'; import { Firestore } from './database'; import { FieldPath } from './field_path'; import { + DocumentData, DocumentReference, PartialWithFieldValue, SetOptions, @@ -86,7 +87,9 @@ export class Transaction { * @param documentRef - A reference to the document to be read. * @returns A `DocumentSnapshot` with the read data. */ - get(documentRef: DocumentReference): Promise> { + get( + documentRef: DocumentReference + ): Promise> { const ref = validateReference(documentRef, this._firestore); const userDataWriter = new LiteUserDataWriter(this._firestore); return this._transaction.lookup([ref._key]).then(docs => { @@ -95,7 +98,7 @@ export class Transaction { } const doc = docs[0]; if (doc.isFoundDocument()) { - return new DocumentSnapshot( + return new DocumentSnapshot( this._firestore, userDataWriter, doc.key, @@ -103,7 +106,7 @@ export class Transaction { ref.converter ); } else if (doc.isNoDocument()) { - return new DocumentSnapshot( + return new DocumentSnapshot( this._firestore, userDataWriter, ref._key, @@ -127,7 +130,10 @@ export class Transaction { * @throws Error - If the provided input is not a valid Firestore document. * @returns This `Transaction` instance. Used for chaining method calls. */ - set(documentRef: DocumentReference, data: WithFieldValue): this; + set( + documentRef: DocumentReference, + data: WithFieldValue + ): this; /** * Writes to the document referred to by the provided {@link * DocumentReference}. If the document does not exist yet, it will be created. @@ -140,14 +146,14 @@ export class Transaction { * @throws Error - If the provided input is not a valid Firestore document. * @returns This `Transaction` instance. Used for chaining method calls. */ - set( - documentRef: DocumentReference, - data: PartialWithFieldValue, + set( + documentRef: DocumentReference, + data: PartialWithFieldValue, options: SetOptions ): this; - set( - documentRef: DocumentReference, - value: PartialWithFieldValue, + set( + documentRef: DocumentReference, + value: PartialWithFieldValue, options?: SetOptions ): this { const ref = validateReference(documentRef, this._firestore); @@ -180,7 +186,10 @@ export class Transaction { * @throws Error - If the provided input is not valid Firestore data. * @returns This `Transaction` instance. Used for chaining method calls. */ - update(documentRef: DocumentReference, data: UpdateData): this; + update( + documentRef: DocumentReference, + data: UpdateData + ): this; /** * Updates fields in the document referred to by the provided {@link * DocumentReference}. The update will fail if applied to a document that does @@ -196,15 +205,15 @@ export class Transaction { * @throws Error - If the provided input is not valid Firestore data. * @returns This `Transaction` instance. Used for chaining method calls. */ - update( - documentRef: DocumentReference, + update( + documentRef: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[] ): this; - update( - documentRef: DocumentReference, - fieldOrUpdateData: string | FieldPath | UpdateData, + update( + documentRef: DocumentReference, + fieldOrUpdateData: string | FieldPath | UpdateData, value?: unknown, ...moreFieldsAndValues: unknown[] ): this { @@ -246,7 +255,9 @@ export class Transaction { * @param documentRef - A reference to the document to be deleted. * @returns This `Transaction` instance. Used for chaining method calls. */ - delete(documentRef: DocumentReference): this { + delete( + documentRef: DocumentReference + ): this { const ref = validateReference(documentRef, this._firestore); this._transaction.delete(ref._key); return this; diff --git a/packages/firestore/src/lite-api/user_data_reader.ts b/packages/firestore/src/lite-api/user_data_reader.ts index 0f869ca87e6..52313b2907a 100644 --- a/packages/firestore/src/lite-api/user_data_reader.ts +++ b/packages/firestore/src/lite-api/user_data_reader.ts @@ -76,13 +76,18 @@ const RESERVED_FIELD_REGEX = /^__.*__$/; * An untyped Firestore Data Converter interface that is shared between the * lite, firestore-exp and classic SDK. */ -export interface UntypedFirestoreDataConverter { - toFirestore(modelObject: WithFieldValue): DocumentData; +export interface UntypedFirestoreDataConverter< + AppModelType, + DbModelType extends DocumentData = DocumentData +> { toFirestore( - modelObject: PartialWithFieldValue, + modelObject: WithFieldValue + ): WithFieldValue; + toFirestore( + modelObject: PartialWithFieldValue, options: SetOptions - ): DocumentData; - fromFirestore(snapshot: unknown, options?: unknown): T; + ): PartialWithFieldValue; + fromFirestore(snapshot: unknown, options?: unknown): AppModelType; } /** The result of parsing document data (e.g. for a setData call). */ diff --git a/packages/firestore/src/lite-api/write_batch.ts b/packages/firestore/src/lite-api/write_batch.ts index e626646f3f7..4c2252d1b24 100644 --- a/packages/firestore/src/lite-api/write_batch.ts +++ b/packages/firestore/src/lite-api/write_batch.ts @@ -26,6 +26,7 @@ import { getDatastore } from './components'; import { Firestore } from './database'; import { FieldPath } from './field_path'; import { + DocumentData, DocumentReference, PartialWithFieldValue, SetOptions, @@ -73,9 +74,9 @@ export class WriteBatch { * @param data - An object of the fields and values for the document. * @returns This `WriteBatch` instance. Used for chaining method calls. */ - set( - documentRef: DocumentReference, - data: WithFieldValue + set( + documentRef: DocumentReference, + data: WithFieldValue ): WriteBatch; /** * Writes to the document referred to by the provided {@link @@ -89,14 +90,14 @@ export class WriteBatch { * @throws Error - If the provided input is not a valid Firestore document. * @returns This `WriteBatch` instance. Used for chaining method calls. */ - set( - documentRef: DocumentReference, - data: PartialWithFieldValue, + set( + documentRef: DocumentReference, + data: PartialWithFieldValue, options: SetOptions ): WriteBatch; - set( - documentRef: DocumentReference, - data: WithFieldValue | PartialWithFieldValue, + set( + documentRef: DocumentReference, + data: WithFieldValue | PartialWithFieldValue, options?: SetOptions ): WriteBatch { this._verifyNotCommitted(); @@ -131,7 +132,10 @@ export class WriteBatch { * @throws Error - If the provided input is not valid Firestore data. * @returns This `WriteBatch` instance. Used for chaining method calls. */ - update(documentRef: DocumentReference, data: UpdateData): WriteBatch; + update( + documentRef: DocumentReference, + data: UpdateData + ): WriteBatch; /** * Updates fields in the document referred to by this {@link * DocumentReference}. The update will fail if applied to a document that does @@ -147,15 +151,15 @@ export class WriteBatch { * @throws Error - If the provided input is not valid Firestore data. * @returns This `WriteBatch` instance. Used for chaining method calls. */ - update( - documentRef: DocumentReference, + update( + documentRef: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[] ): WriteBatch; - update( - documentRef: DocumentReference, - fieldOrUpdateData: string | FieldPath | UpdateData, + update( + documentRef: DocumentReference, + fieldOrUpdateData: string | FieldPath | UpdateData, value?: unknown, ...moreFieldsAndValues: unknown[] ): WriteBatch { @@ -200,7 +204,9 @@ export class WriteBatch { * @param documentRef - A reference to the document to be deleted. * @returns This `WriteBatch` instance. Used for chaining method calls. */ - delete(documentRef: DocumentReference): WriteBatch { + delete( + documentRef: DocumentReference + ): WriteBatch { this._verifyNotCommitted(); const ref = validateReference(documentRef, this._firestore); this._mutations = this._mutations.concat( @@ -242,10 +248,15 @@ export class WriteBatch { } } -export function validateReference( - documentRef: DocumentReference | Compat>, +export function validateReference< + AppModelType, + DbModelType extends DocumentData +>( + documentRef: + | DocumentReference + | Compat>, firestore: Firestore -): DocumentReference { +): DocumentReference { documentRef = getModularInstance(documentRef); if (documentRef.firestore !== firestore) { @@ -254,7 +265,7 @@ export function validateReference( 'Provided document reference is from a different Firestore instance.' ); } else { - return documentRef as DocumentReference; + return documentRef as DocumentReference; } } diff --git a/packages/firestore/test/lite/integration.test.ts b/packages/firestore/test/lite/integration.test.ts index 0c8515f038c..8dee373a867 100644 --- a/packages/firestore/test/lite/integration.test.ts +++ b/packages/firestore/test/lite/integration.test.ts @@ -78,6 +78,7 @@ import { updateDoc } from '../../src/lite-api/reference_impl'; import { + FirestoreDataConverter, snapshotEqual, QuerySnapshot, QueryDocumentSnapshot @@ -428,26 +429,28 @@ describe('getDoc()', () => { * DocumentReference-based mutation API. */ interface MutationTester { - set( - documentRef: DocumentReference, - data: WithFieldValue + set( + documentRef: DocumentReference, + data: WithFieldValue ): Promise; - set( - documentRef: DocumentReference, - data: PartialWithFieldValue, + set( + documentRef: DocumentReference, + data: PartialWithFieldValue, options: SetOptions ): Promise; - update( - documentRef: DocumentReference, - data: UpdateData + update( + documentRef: DocumentReference, + data: UpdateData ): Promise; - update( - documentRef: DocumentReference, + update( + documentRef: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[] ): Promise; - delete(documentRef: DocumentReference): Promise; + delete( + documentRef: DocumentReference + ): Promise; } genericMutationTests({ @@ -458,15 +461,17 @@ genericMutationTests({ describe('WriteBatch', () => { class WriteBatchTester implements MutationTester { - delete(ref: DocumentReference): Promise { + delete( + ref: DocumentReference + ): Promise { const batch = writeBatch(ref.firestore); batch.delete(ref); return batch.commit(); } - set( - ref: DocumentReference, - data: PartialWithFieldValue, + set( + ref: DocumentReference, + data: PartialWithFieldValue, options?: SetOptions ): Promise { const batch = writeBatch(ref.firestore); @@ -476,9 +481,9 @@ describe('WriteBatch', () => { return batch.commit(); } - update( - ref: DocumentReference, - dataOrField: UpdateData | string | FieldPath, + update( + ref: DocumentReference, + dataOrField: UpdateData | string | FieldPath, value?: unknown, ...moreFieldsAndValues: unknown[] ): Promise { @@ -521,29 +526,31 @@ describe('WriteBatch', () => { describe('Transaction', () => { class TransactionTester implements MutationTester { - delete(ref: DocumentReference): Promise { + delete( + ref: DocumentReference + ): Promise { return runTransaction(ref.firestore, async transaction => { transaction.delete(ref); }); } - set( - ref: DocumentReference, - data: PartialWithFieldValue, + set( + ref: DocumentReference, + data: PartialWithFieldValue, options?: SetOptions ): Promise { return runTransaction(ref.firestore, async transaction => { if (options) { transaction.set(ref, data, options); } else { - transaction.set(ref, data as WithFieldValue); + transaction.set(ref, data as WithFieldValue); } }); } - update( - ref: DocumentReference, - dataOrField: UpdateData | string | FieldPath, + update( + ref: DocumentReference, + dataOrField: UpdateData | string | FieldPath, value?: unknown, ...moreFieldsAndValues: unknown[] ): Promise { @@ -556,7 +563,7 @@ describe('Transaction', () => { ...moreFieldsAndValues ); } else { - transaction.update(ref, dataOrField as UpdateData); + transaction.update(ref, dataOrField as UpdateData); } }); } @@ -1385,7 +1392,7 @@ describe('withConverter() support', () => { ) {} } - const testConverter = { + const testConverter: FirestoreDataConverter = { toFirestore(testObj: WithFieldValue) { return { ...testObj }; }, @@ -1780,8 +1787,7 @@ describe('withConverter() support', () => { it('supports string-separated fields', () => { return withTestDocAndInitialData(initialData, async docRef => { - const testDocRef: DocumentReference = - docRef.withConverter(testConverter); + const testDocRef = docRef.withConverter(testConverter); await updateDoc(testDocRef, { // @ts-expect-error outerString: 3, @@ -1895,7 +1901,10 @@ describe('withConverter() support', () => { | { requiredNumber: number }; } - const testConverterUnion = { + const testConverterUnion: FirestoreDataConverter< + TestObjectUnion, + TestObjectUnion + > = { toFirestore(testObj: WithFieldValue) { return { ...testObj }; }, @@ -1909,8 +1918,7 @@ describe('withConverter() support', () => { }; return withTestDocAndInitialData(initialData, async docRef => { - const testDocRef: DocumentReference = - docRef.withConverter(testConverterUnion); + const testDocRef = docRef.withConverter(testConverterUnion); await updateDoc(testDocRef, { nested: { @@ -1943,8 +1951,7 @@ describe('withConverter() support', () => { it('checks for nonexistent fields', () => { return withTestDocAndInitialData(initialData, async docRef => { - const testDocRef: DocumentReference = - docRef.withConverter(testConverter); + const testDocRef = docRef.withConverter(testConverter); // Top-level fields. await updateDoc(testDocRef, { From 802b1fb3aa61118136c7fce192fdacdeb2fc3fd5 Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Fri, 19 May 2023 14:10:48 -0400 Subject: [PATCH 02/10] Update common/api-review/firestore.api.md and common/api-review/firestore-lite.api.md --- common/api-review/firestore-lite.api.md | 128 +++++++++--------- common/api-review/firestore.api.md | 166 ++++++++++++------------ 2 files changed, 147 insertions(+), 147 deletions(-) diff --git a/common/api-review/firestore-lite.api.md b/common/api-review/firestore-lite.api.md index 35802afacb7..a1592cd14f3 100644 --- a/common/api-review/firestore-lite.api.md +++ b/common/api-review/firestore-lite.api.md @@ -10,7 +10,7 @@ import { FirebaseError } from '@firebase/util'; import { LogLevelString as LogLevel } from '@firebase/logger'; // @public -export function addDoc(reference: CollectionReference, data: WithFieldValue): Promise>; +export function addDoc(reference: CollectionReference, data: WithFieldValue): Promise>; // @public export type AddPrefixToKeys> = { @@ -26,14 +26,14 @@ export class AggregateField { export type AggregateFieldType = AggregateField; // @public -export class AggregateQuerySnapshot { - data(): AggregateSpecData; - readonly query: Query; +export class AggregateQuerySnapshot { + data(): AggregateSpecData; + readonly query: Query; readonly type = "AggregateQuerySnapshot"; } // @public -export function aggregateQuerySnapshotEqual(left: AggregateQuerySnapshot, right: AggregateQuerySnapshot): boolean; +export function aggregateQuerySnapshotEqual(left: AggregateQuerySnapshot, right: AggregateQuerySnapshot): boolean; // @public export interface AggregateSpec { @@ -69,25 +69,25 @@ export class Bytes { export type ChildUpdateFields = V extends Record ? AddPrefixToKeys> : never; // @public -export function collection(firestore: Firestore, path: string, ...pathSegments: string[]): CollectionReference; +export function collection(firestore: Firestore, path: string, ...pathSegments: string[]): CollectionReference; // @public -export function collection(reference: CollectionReference, path: string, ...pathSegments: string[]): CollectionReference; +export function collection(reference: CollectionReference, path: string, ...pathSegments: string[]): CollectionReference; // @public -export function collection(reference: DocumentReference, path: string, ...pathSegments: string[]): CollectionReference; +export function collection(reference: DocumentReference, path: string, ...pathSegments: string[]): CollectionReference; // @public -export function collectionGroup(firestore: Firestore, collectionId: string): Query; +export function collectionGroup(firestore: Firestore, collectionId: string): Query; // @public -export class CollectionReference extends Query { +export class CollectionReference extends Query { get id(): string; - get parent(): DocumentReference | null; + get parent(): DocumentReference | null; get path(): string; readonly type = "collection"; - withConverter(converter: FirestoreDataConverter): CollectionReference; - withConverter(converter: null): CollectionReference; + withConverter(converter: FirestoreDataConverter): CollectionReference; + withConverter(converter: null): CollectionReference; } // @public @@ -96,19 +96,19 @@ export function connectFirestoreEmulator(firestore: Firestore, host: string, por }): void; // @public -export function deleteDoc(reference: DocumentReference): Promise; +export function deleteDoc(reference: DocumentReference): Promise; // @public export function deleteField(): FieldValue; // @public -export function doc(firestore: Firestore, path: string, ...pathSegments: string[]): DocumentReference; +export function doc(firestore: Firestore, path: string, ...pathSegments: string[]): DocumentReference; // @public -export function doc(reference: CollectionReference, path?: string, ...pathSegments: string[]): DocumentReference; +export function doc(reference: CollectionReference, path?: string, ...pathSegments: string[]): DocumentReference; // @public -export function doc(reference: DocumentReference, path: string, ...pathSegments: string[]): DocumentReference; +export function doc(reference: DocumentReference, path: string, ...pathSegments: string[]): DocumentReference; // @public export interface DocumentData { @@ -119,25 +119,25 @@ export interface DocumentData { export function documentId(): FieldPath; // @public -export class DocumentReference { - readonly converter: FirestoreDataConverter | null; +export class DocumentReference { + readonly converter: FirestoreDataConverter | null; readonly firestore: Firestore; get id(): string; - get parent(): CollectionReference; + get parent(): CollectionReference; get path(): string; readonly type = "document"; - withConverter(converter: FirestoreDataConverter): DocumentReference; - withConverter(converter: null): DocumentReference; + withConverter(converter: FirestoreDataConverter): DocumentReference; + withConverter(converter: null): DocumentReference; } // @public -export class DocumentSnapshot { +export class DocumentSnapshot { protected constructor(); - data(): T | undefined; - exists(): this is QueryDocumentSnapshot; + data(): AppModelType | undefined; + exists(): this is QueryDocumentSnapshot; get(fieldPath: string | FieldPath): any; get id(): string; - get ref(): DocumentReference; + get ref(): DocumentReference; } export { EmulatorMockTokenOptions } @@ -173,10 +173,10 @@ export class Firestore { } // @public -export interface FirestoreDataConverter { - fromFirestore(snapshot: QueryDocumentSnapshot): T; - toFirestore(modelObject: WithFieldValue): DocumentData; - toFirestore(modelObject: PartialWithFieldValue, options: SetOptions): DocumentData; +export interface FirestoreDataConverter { + fromFirestore(snapshot: QueryDocumentSnapshot): AppModelType; + toFirestore(modelObject: WithFieldValue): WithFieldValue; + toFirestore(modelObject: PartialWithFieldValue, options: SetOptions): PartialWithFieldValue; } // @public @@ -202,15 +202,15 @@ export class GeoPoint { } // @public -export function getCount(query: Query): Promise(query: Query): Promise; -}>>; +}, AppModelType, DbModelType>>; // @public -export function getDoc(reference: DocumentReference): Promise>; +export function getDoc(reference: DocumentReference): Promise>; // @public -export function getDocs(query: Query): Promise>; +export function getDocs(query: Query): Promise>; // @public export function getFirestore(): Firestore; @@ -255,20 +255,20 @@ export type PartialWithFieldValue = Partial | (T extends Primitive ? T : T export type Primitive = string | number | boolean | undefined | null; // @public -export class Query { +export class Query { protected constructor(); - readonly converter: FirestoreDataConverter | null; + readonly converter: FirestoreDataConverter | null; readonly firestore: Firestore; readonly type: 'query' | 'collection'; - withConverter(converter: null): Query; - withConverter(converter: FirestoreDataConverter): Query; + withConverter(converter: null): Query; + withConverter(converter: FirestoreDataConverter): Query; } // @public -export function query(query: Query, compositeFilter: QueryCompositeFilterConstraint, ...queryConstraints: QueryNonFilterConstraint[]): Query; +export function query(query: Query, compositeFilter: QueryCompositeFilterConstraint, ...queryConstraints: QueryNonFilterConstraint[]): Query; // @public -export function query(query: Query, ...queryConstraints: QueryConstraint[]): Query; +export function query(query: Query, ...queryConstraints: QueryConstraint[]): Query; // @public export class QueryCompositeFilterConstraint { @@ -284,9 +284,9 @@ export abstract class QueryConstraint { export type QueryConstraintType = 'where' | 'orderBy' | 'limit' | 'limitToLast' | 'startAt' | 'startAfter' | 'endAt' | 'endBefore'; // @public -export class QueryDocumentSnapshot extends DocumentSnapshot { +export class QueryDocumentSnapshot extends DocumentSnapshot { // @override - data(): T; + data(): AppModelType; } // @public @@ -295,7 +295,7 @@ export class QueryEndAtConstraint extends QueryConstraint { } // @public -export function queryEqual(left: Query, right: Query): boolean; +export function queryEqual(left: Query, right: Query): boolean; // @public export class QueryFieldFilterConstraint extends QueryConstraint { @@ -319,11 +319,11 @@ export class QueryOrderByConstraint extends QueryConstraint { } // @public -export class QuerySnapshot { - get docs(): Array>; +export class QuerySnapshot { + get docs(): Array>; get empty(): boolean; - forEach(callback: (result: QueryDocumentSnapshot) => void, thisArg?: unknown): void; - readonly query: Query; + forEach(callback: (result: QueryDocumentSnapshot) => void, thisArg?: unknown): void; + readonly query: Query; get size(): number; } @@ -333,7 +333,7 @@ export class QueryStartAtConstraint extends QueryConstraint { } // @public -export function refEqual(left: DocumentReference | CollectionReference, right: DocumentReference | CollectionReference): boolean; +export function refEqual(left: DocumentReference | CollectionReference, right: DocumentReference | CollectionReference): boolean; // @public export function runTransaction(firestore: Firestore, updateFunction: (transaction: Transaction) => Promise, options?: TransactionOptions): Promise; @@ -342,10 +342,10 @@ export function runTransaction(firestore: Firestore, updateFunction: (transac export function serverTimestamp(): FieldValue; // @public -export function setDoc(reference: DocumentReference, data: WithFieldValue): Promise; +export function setDoc(reference: DocumentReference, data: WithFieldValue): Promise; // @public -export function setDoc(reference: DocumentReference, data: PartialWithFieldValue, options: SetOptions): Promise; +export function setDoc(reference: DocumentReference, data: PartialWithFieldValue, options: SetOptions): Promise; // @public export function setLogLevel(logLevel: LogLevel): void; @@ -365,7 +365,7 @@ export interface Settings { } // @public -export function snapshotEqual(left: DocumentSnapshot | QuerySnapshot, right: DocumentSnapshot | QuerySnapshot): boolean; +export function snapshotEqual(left: DocumentSnapshot | QuerySnapshot, right: DocumentSnapshot | QuerySnapshot): boolean; // @public export function startAfter(snapshot: DocumentSnapshot): QueryStartAtConstraint; @@ -405,12 +405,12 @@ export class Timestamp { // @public export class Transaction { - delete(documentRef: DocumentReference): this; - get(documentRef: DocumentReference): Promise>; - set(documentRef: DocumentReference, data: WithFieldValue): this; - set(documentRef: DocumentReference, data: PartialWithFieldValue, options: SetOptions): this; - update(documentRef: DocumentReference, data: UpdateData): this; - update(documentRef: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): this; + delete(documentRef: DocumentReference): this; + get(documentRef: DocumentReference): Promise>; + set(documentRef: DocumentReference, data: WithFieldValue): this; + set(documentRef: DocumentReference, data: PartialWithFieldValue, options: SetOptions): this; + update(documentRef: DocumentReference, data: UpdateData): this; + update(documentRef: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): this; } // @public @@ -427,10 +427,10 @@ export type UpdateData = T extends Primitive ? T : T extends {} ? { } & NestedUpdateFields : Partial; // @public -export function updateDoc(reference: DocumentReference, data: UpdateData): Promise; +export function updateDoc(reference: DocumentReference, data: UpdateData): Promise; // @public -export function updateDoc(reference: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): Promise; +export function updateDoc(reference: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): Promise; // @public export function where(fieldPath: string | FieldPath, opStr: WhereFilterOp, value: unknown): QueryFieldFilterConstraint; @@ -446,11 +446,11 @@ export type WithFieldValue = T | (T extends Primitive ? T : T extends {} ? { // @public export class WriteBatch { commit(): Promise; - delete(documentRef: DocumentReference): WriteBatch; - set(documentRef: DocumentReference, data: WithFieldValue): WriteBatch; - set(documentRef: DocumentReference, data: PartialWithFieldValue, options: SetOptions): WriteBatch; - update(documentRef: DocumentReference, data: UpdateData): WriteBatch; - update(documentRef: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): WriteBatch; + delete(documentRef: DocumentReference): WriteBatch; + set(documentRef: DocumentReference, data: WithFieldValue): WriteBatch; + set(documentRef: DocumentReference, data: PartialWithFieldValue, options: SetOptions): WriteBatch; + update(documentRef: DocumentReference, data: UpdateData): WriteBatch; + update(documentRef: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): WriteBatch; } // @public diff --git a/common/api-review/firestore.api.md b/common/api-review/firestore.api.md index 580320b0aa3..3ab6a88cd74 100644 --- a/common/api-review/firestore.api.md +++ b/common/api-review/firestore.api.md @@ -10,7 +10,7 @@ import { FirebaseError } from '@firebase/util'; import { LogLevelString as LogLevel } from '@firebase/logger'; // @public -export function addDoc(reference: CollectionReference, data: WithFieldValue): Promise>; +export function addDoc(reference: CollectionReference, data: WithFieldValue): Promise>; // @public export type AddPrefixToKeys> = { @@ -26,14 +26,14 @@ export class AggregateField { export type AggregateFieldType = AggregateField; // @public -export class AggregateQuerySnapshot { - data(): AggregateSpecData; - readonly query: Query; +export class AggregateQuerySnapshot { + data(): AggregateSpecData; + readonly query: Query; readonly type = "AggregateQuerySnapshot"; } // @public -export function aggregateQuerySnapshotEqual(left: AggregateQuerySnapshot, right: AggregateQuerySnapshot): boolean; +export function aggregateQuerySnapshotEqual(left: AggregateQuerySnapshot, right: AggregateQuerySnapshot): boolean; // @public export interface AggregateSpec { @@ -75,25 +75,25 @@ export type ChildUpdateFields = V extends Record; // @public -export function collection(firestore: Firestore, path: string, ...pathSegments: string[]): CollectionReference; +export function collection(firestore: Firestore, path: string, ...pathSegments: string[]): CollectionReference; // @public -export function collection(reference: CollectionReference, path: string, ...pathSegments: string[]): CollectionReference; +export function collection(reference: CollectionReference, path: string, ...pathSegments: string[]): CollectionReference; // @public -export function collection(reference: DocumentReference, path: string, ...pathSegments: string[]): CollectionReference; +export function collection(reference: DocumentReference, path: string, ...pathSegments: string[]): CollectionReference; // @public -export function collectionGroup(firestore: Firestore, collectionId: string): Query; +export function collectionGroup(firestore: Firestore, collectionId: string): Query; // @public -export class CollectionReference extends Query { +export class CollectionReference extends Query { get id(): string; - get parent(): DocumentReference | null; + get parent(): DocumentReference | null; get path(): string; readonly type = "collection"; - withConverter(converter: FirestoreDataConverter): CollectionReference; - withConverter(converter: null): CollectionReference; + withConverter(converter: FirestoreDataConverter): CollectionReference; + withConverter(converter: null): CollectionReference; } // @public @@ -102,7 +102,7 @@ export function connectFirestoreEmulator(firestore: Firestore, host: string, por }): void; // @public -export function deleteDoc(reference: DocumentReference): Promise; +export function deleteDoc(reference: DocumentReference): Promise; // @public export function deleteField(): FieldValue; @@ -111,17 +111,17 @@ export function deleteField(): FieldValue; export function disableNetwork(firestore: Firestore): Promise; // @public -export function doc(firestore: Firestore, path: string, ...pathSegments: string[]): DocumentReference; +export function doc(firestore: Firestore, path: string, ...pathSegments: string[]): DocumentReference; // @public -export function doc(reference: CollectionReference, path?: string, ...pathSegments: string[]): DocumentReference; +export function doc(reference: CollectionReference, path?: string, ...pathSegments: string[]): DocumentReference; // @public -export function doc(reference: DocumentReference, path: string, ...pathSegments: string[]): DocumentReference; +export function doc(reference: DocumentReference, path: string, ...pathSegments: string[]): DocumentReference; // @public -export interface DocumentChange { - readonly doc: QueryDocumentSnapshot; +export interface DocumentChange { + readonly doc: QueryDocumentSnapshot; readonly newIndex: number; readonly oldIndex: number; readonly type: DocumentChangeType; @@ -139,26 +139,26 @@ export interface DocumentData { export function documentId(): FieldPath; // @public -export class DocumentReference { - readonly converter: FirestoreDataConverter | null; +export class DocumentReference { + readonly converter: FirestoreDataConverter | null; readonly firestore: Firestore; get id(): string; - get parent(): CollectionReference; + get parent(): CollectionReference; get path(): string; readonly type = "document"; - withConverter(converter: FirestoreDataConverter): DocumentReference; - withConverter(converter: null): DocumentReference; + withConverter(converter: FirestoreDataConverter): DocumentReference; + withConverter(converter: null): DocumentReference; } // @public -export class DocumentSnapshot { +export class DocumentSnapshot { protected constructor(); - data(options?: SnapshotOptions): T | undefined; - exists(): this is QueryDocumentSnapshot; + data(options?: SnapshotOptions): AppModelType | undefined; + exists(): this is QueryDocumentSnapshot; get(fieldPath: string | FieldPath, options?: SnapshotOptions): any; get id(): string; readonly metadata: SnapshotMetadata; - get ref(): DocumentReference; + get ref(): DocumentReference; } export { EmulatorMockTokenOptions } @@ -208,10 +208,10 @@ export class Firestore { } // @public -export interface FirestoreDataConverter { - fromFirestore(snapshot: QueryDocumentSnapshot, options?: SnapshotOptions): T; - toFirestore(modelObject: WithFieldValue): DocumentData; - toFirestore(modelObject: PartialWithFieldValue, options: SetOptions): DocumentData; +export interface FirestoreDataConverter { + fromFirestore(snapshot: QueryDocumentSnapshot, options?: SnapshotOptions): AppModelType; + toFirestore(modelObject: WithFieldValue): WithFieldValue; + toFirestore(modelObject: PartialWithFieldValue, options: SetOptions): PartialWithFieldValue; } // @public @@ -252,27 +252,27 @@ export class GeoPoint { } // @public -export function getCountFromServer(query: Query): Promise(query: Query): Promise; -}>>; +}, AppModelType, DbModelType>>; // @public -export function getDoc(reference: DocumentReference): Promise>; +export function getDoc(reference: DocumentReference): Promise>; // @public -export function getDocFromCache(reference: DocumentReference): Promise>; +export function getDocFromCache(reference: DocumentReference): Promise>; // @public -export function getDocFromServer(reference: DocumentReference): Promise>; +export function getDocFromServer(reference: DocumentReference): Promise>; // @public -export function getDocs(query: Query): Promise>; +export function getDocs(query: Query): Promise>; // @public -export function getDocsFromCache(query: Query): Promise>; +export function getDocsFromCache(query: Query): Promise>; // @public -export function getDocsFromServer(query: Query): Promise>; +export function getDocsFromServer(query: Query): Promise>; // @public export function getFirestore(app: FirebaseApp): Firestore; @@ -383,44 +383,44 @@ export type NestedUpdateFields> = UnionToInter }[keyof T & string]>; // @public -export function onSnapshot(reference: DocumentReference, observer: { - next?: (snapshot: DocumentSnapshot) => void; +export function onSnapshot(reference: DocumentReference, observer: { + next?: (snapshot: DocumentSnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; }): Unsubscribe; // @public -export function onSnapshot(reference: DocumentReference, options: SnapshotListenOptions, observer: { - next?: (snapshot: DocumentSnapshot) => void; +export function onSnapshot(reference: DocumentReference, options: SnapshotListenOptions, observer: { + next?: (snapshot: DocumentSnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; }): Unsubscribe; // @public -export function onSnapshot(reference: DocumentReference, onNext: (snapshot: DocumentSnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe; +export function onSnapshot(reference: DocumentReference, onNext: (snapshot: DocumentSnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe; // @public -export function onSnapshot(reference: DocumentReference, options: SnapshotListenOptions, onNext: (snapshot: DocumentSnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe; +export function onSnapshot(reference: DocumentReference, options: SnapshotListenOptions, onNext: (snapshot: DocumentSnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe; // @public -export function onSnapshot(query: Query, observer: { - next?: (snapshot: QuerySnapshot) => void; +export function onSnapshot(query: Query, observer: { + next?: (snapshot: QuerySnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; }): Unsubscribe; // @public -export function onSnapshot(query: Query, options: SnapshotListenOptions, observer: { - next?: (snapshot: QuerySnapshot) => void; +export function onSnapshot(query: Query, options: SnapshotListenOptions, observer: { + next?: (snapshot: QuerySnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; }): Unsubscribe; // @public -export function onSnapshot(query: Query, onNext: (snapshot: QuerySnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe; +export function onSnapshot(query: Query, onNext: (snapshot: QuerySnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe; // @public -export function onSnapshot(query: Query, options: SnapshotListenOptions, onNext: (snapshot: QuerySnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe; +export function onSnapshot(query: Query, options: SnapshotListenOptions, onNext: (snapshot: QuerySnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe; // @public export function onSnapshotsInSync(firestore: Firestore, observer: { @@ -496,20 +496,20 @@ export type PersistentTabManager = PersistentSingleTabManager | PersistentMultip export type Primitive = string | number | boolean | undefined | null; // @public -export class Query { +export class Query { protected constructor(); - readonly converter: FirestoreDataConverter | null; + readonly converter: FirestoreDataConverter | null; readonly firestore: Firestore; readonly type: 'query' | 'collection'; - withConverter(converter: null): Query; - withConverter(converter: FirestoreDataConverter): Query; + withConverter(converter: null): Query; + withConverter(converter: FirestoreDataConverter): Query; } // @public -export function query(query: Query, compositeFilter: QueryCompositeFilterConstraint, ...queryConstraints: QueryNonFilterConstraint[]): Query; +export function query(query: Query, compositeFilter: QueryCompositeFilterConstraint, ...queryConstraints: QueryNonFilterConstraint[]): Query; // @public -export function query(query: Query, ...queryConstraints: QueryConstraint[]): Query; +export function query(query: Query, ...queryConstraints: QueryConstraint[]): Query; // @public export class QueryCompositeFilterConstraint { @@ -525,9 +525,9 @@ export abstract class QueryConstraint { export type QueryConstraintType = 'where' | 'orderBy' | 'limit' | 'limitToLast' | 'startAt' | 'startAfter' | 'endAt' | 'endBefore'; // @public -export class QueryDocumentSnapshot extends DocumentSnapshot { +export class QueryDocumentSnapshot extends DocumentSnapshot { // @override - data(options?: SnapshotOptions): T; + data(options?: SnapshotOptions): AppModelType; } // @public @@ -536,7 +536,7 @@ export class QueryEndAtConstraint extends QueryConstraint { } // @public -export function queryEqual(left: Query, right: Query): boolean; +export function queryEqual(left: Query, right: Query): boolean; // @public export class QueryFieldFilterConstraint extends QueryConstraint { @@ -560,13 +560,13 @@ export class QueryOrderByConstraint extends QueryConstraint { } // @public -export class QuerySnapshot { - docChanges(options?: SnapshotListenOptions): Array>; - get docs(): Array>; +export class QuerySnapshot { + docChanges(options?: SnapshotListenOptions): Array>; + get docs(): Array>; get empty(): boolean; - forEach(callback: (result: QueryDocumentSnapshot) => void, thisArg?: unknown): void; + forEach(callback: (result: QueryDocumentSnapshot) => void, thisArg?: unknown): void; readonly metadata: SnapshotMetadata; - readonly query: Query; + readonly query: Query; get size(): number; } @@ -576,7 +576,7 @@ export class QueryStartAtConstraint extends QueryConstraint { } // @public -export function refEqual(left: DocumentReference | CollectionReference, right: DocumentReference | CollectionReference): boolean; +export function refEqual(left: DocumentReference | CollectionReference, right: DocumentReference | CollectionReference): boolean; // @public export function runTransaction(firestore: Firestore, updateFunction: (transaction: Transaction) => Promise, options?: TransactionOptions): Promise; @@ -585,10 +585,10 @@ export function runTransaction(firestore: Firestore, updateFunction: (transac export function serverTimestamp(): FieldValue; // @public -export function setDoc(reference: DocumentReference, data: WithFieldValue): Promise; +export function setDoc(reference: DocumentReference, data: WithFieldValue): Promise; // @public -export function setDoc(reference: DocumentReference, data: PartialWithFieldValue, options: SetOptions): Promise; +export function setDoc(reference: DocumentReference, data: PartialWithFieldValue, options: SetOptions): Promise; // @beta export function setIndexConfiguration(firestore: Firestore, configuration: IndexConfiguration): Promise; @@ -607,7 +607,7 @@ export type SetOptions = { }; // @public -export function snapshotEqual(left: DocumentSnapshot | QuerySnapshot, right: DocumentSnapshot | QuerySnapshot): boolean; +export function snapshotEqual(left: DocumentSnapshot | QuerySnapshot, right: DocumentSnapshot | QuerySnapshot): boolean; // @public export interface SnapshotListenOptions { @@ -667,12 +667,12 @@ export class Timestamp { // @public export class Transaction { - delete(documentRef: DocumentReference): this; - get(documentRef: DocumentReference): Promise>; - set(documentRef: DocumentReference, data: WithFieldValue): this; - set(documentRef: DocumentReference, data: PartialWithFieldValue, options: SetOptions): this; - update(documentRef: DocumentReference, data: UpdateData): this; - update(documentRef: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): this; + delete(documentRef: DocumentReference): this; + get(documentRef: DocumentReference): Promise>; + set(documentRef: DocumentReference, data: WithFieldValue): this; + set(documentRef: DocumentReference, data: PartialWithFieldValue, options: SetOptions): this; + update(documentRef: DocumentReference, data: UpdateData): this; + update(documentRef: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): this; } // @public @@ -694,10 +694,10 @@ export type UpdateData = T extends Primitive ? T : T extends {} ? { } & NestedUpdateFields : Partial; // @public -export function updateDoc(reference: DocumentReference, data: UpdateData): Promise; +export function updateDoc(reference: DocumentReference, data: UpdateData): Promise; // @public -export function updateDoc(reference: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): Promise; +export function updateDoc(reference: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): Promise; // @public export function waitForPendingWrites(firestore: Firestore): Promise; @@ -716,11 +716,11 @@ export type WithFieldValue = T | (T extends Primitive ? T : T extends {} ? { // @public export class WriteBatch { commit(): Promise; - delete(documentRef: DocumentReference): WriteBatch; - set(documentRef: DocumentReference, data: WithFieldValue): WriteBatch; - set(documentRef: DocumentReference, data: PartialWithFieldValue, options: SetOptions): WriteBatch; - update(documentRef: DocumentReference, data: UpdateData): WriteBatch; - update(documentRef: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): WriteBatch; + delete(documentRef: DocumentReference): WriteBatch; + set(documentRef: DocumentReference, data: WithFieldValue): WriteBatch; + set(documentRef: DocumentReference, data: PartialWithFieldValue, options: SetOptions): WriteBatch; + update(documentRef: DocumentReference, data: UpdateData): WriteBatch; + update(documentRef: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): WriteBatch; } // @public From e2d238d9d451913acf5f4a87a6a822e833783a1e Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Fri, 19 May 2023 14:11:23 -0400 Subject: [PATCH 03/10] yarn docgen devsite --- .../firestore_.aggregatequerysnapshot.md | 10 +- .../firestore_.collectionreference.md | 18 +- docs-devsite/firestore_.documentchange.md | 6 +- docs-devsite/firestore_.documentreference.md | 20 +- docs-devsite/firestore_.documentsnapshot.md | 14 +- .../firestore_.firestoredataconverter.md | 20 +- docs-devsite/firestore_.md | 206 +++++++++--------- docs-devsite/firestore_.query.md | 16 +- .../firestore_.querydocumentsnapshot.md | 8 +- docs-devsite/firestore_.querysnapshot.md | 18 +- docs-devsite/firestore_.transaction.md | 32 +-- docs-devsite/firestore_.writebatch.md | 26 +-- .../firestore_lite.aggregatequerysnapshot.md | 10 +- .../firestore_lite.collectionreference.md | 18 +- .../firestore_lite.documentreference.md | 20 +- .../firestore_lite.documentsnapshot.md | 14 +- .../firestore_lite.firestoredataconverter.md | 20 +- docs-devsite/firestore_lite.md | 126 +++++------ docs-devsite/firestore_lite.query.md | 16 +- .../firestore_lite.querydocumentsnapshot.md | 8 +- docs-devsite/firestore_lite.querysnapshot.md | 14 +- docs-devsite/firestore_lite.transaction.md | 32 +-- docs-devsite/firestore_lite.writebatch.md | 26 +-- 23 files changed, 349 insertions(+), 349 deletions(-) diff --git a/docs-devsite/firestore_.aggregatequerysnapshot.md b/docs-devsite/firestore_.aggregatequerysnapshot.md index 1cf63b5db8b..875ed923174 100644 --- a/docs-devsite/firestore_.aggregatequerysnapshot.md +++ b/docs-devsite/firestore_.aggregatequerysnapshot.md @@ -15,14 +15,14 @@ The results of executing an aggregation query. Signature: ```typescript -export declare class AggregateQuerySnapshot +export declare class AggregateQuerySnapshot ``` ## Properties | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [query](./firestore_.aggregatequerysnapshot.md#aggregatequerysnapshotquery) | | [Query](./firestore_.query.md#query_class)<unknown> | The underlying query over which the aggregations recorded in this AggregateQuerySnapshot were performed. | +| [query](./firestore_.aggregatequerysnapshot.md#aggregatequerysnapshotquery) | | [Query](./firestore_.query.md#query_class)<AppModelType, DbModelType> | The underlying query over which the aggregations recorded in this AggregateQuerySnapshot were performed. | | [type](./firestore_.aggregatequerysnapshot.md#aggregatequerysnapshottype) | | (not declared) | A type string to uniquely identify instances of this class. | ## Methods @@ -38,7 +38,7 @@ The underlying query over which the aggregations recorded in this `AggregateQuer Signature: ```typescript -readonly query: Query; +readonly query: Query; ``` ## AggregateQuerySnapshot.type @@ -60,11 +60,11 @@ The keys of the returned object will be the same as those of the `AggregateSpec` Signature: ```typescript -data(): AggregateSpecData; +data(): AggregateSpecData; ``` Returns: -[AggregateSpecData](./firestore_.md#aggregatespecdata)<T> +[AggregateSpecData](./firestore_.md#aggregatespecdata)<AggregateSpecType> The results of the aggregations performed over the underlying query. diff --git a/docs-devsite/firestore_.collectionreference.md b/docs-devsite/firestore_.collectionreference.md index 56c81c6b245..81fd7e218dc 100644 --- a/docs-devsite/firestore_.collectionreference.md +++ b/docs-devsite/firestore_.collectionreference.md @@ -15,16 +15,16 @@ A `CollectionReference` object can be used for adding documents, getting documen Signature: ```typescript -export declare class CollectionReference extends Query +export declare class CollectionReference extends Query ``` -Extends: [Query](./firestore_.query.md#query_class)<T> +Extends: [Query](./firestore_.query.md#query_class)<AppModelType, DbModelType> ## Properties | Property | Modifiers | Type | Description | | --- | --- | --- | --- | | [id](./firestore_.collectionreference.md#collectionreferenceid) | | string | The collection's identifier. | -| [parent](./firestore_.collectionreference.md#collectionreferenceparent) | | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface)> \| null | A reference to the containing DocumentReference if this is a subcollection. If this isn't a subcollection, the reference is null. | +| [parent](./firestore_.collectionreference.md#collectionreferenceparent) | | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface), [DocumentData](./firestore_.documentdata.md#documentdata_interface)> \| null | A reference to the containing DocumentReference if this is a subcollection. If this isn't a subcollection, the reference is null. | | [path](./firestore_.collectionreference.md#collectionreferencepath) | | string | A string representing the path of the referenced collection (relative to the root of the database). | | [type](./firestore_.collectionreference.md#collectionreferencetype) | | (not declared) | The type of this Firestore reference. | @@ -52,7 +52,7 @@ A reference to the containing `DocumentReference` if this is a subcollection. If Signature: ```typescript -get parent(): DocumentReference | null; +get parent(): DocumentReference | null; ``` ## CollectionReference.path @@ -82,18 +82,18 @@ Applies a custom data converter to this `CollectionReference`, allowing Signature: ```typescript -withConverter(converter: FirestoreDataConverter): CollectionReference; +withConverter(converter: FirestoreDataConverter): CollectionReference; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| converter | [FirestoreDataConverter](./firestore_.firestoredataconverter.md#firestoredataconverter_interface)<U> | Converts objects to and from Firestore. | +| converter | [FirestoreDataConverter](./firestore_.firestoredataconverter.md#firestoredataconverter_interface)<NewAppModelType, NewDbModelType> | Converts objects to and from Firestore. | Returns: -[CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<U> +[CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<NewAppModelType, NewDbModelType> A `CollectionReference` that uses the provided converter. @@ -104,7 +104,7 @@ Removes the current converter. Signature: ```typescript -withConverter(converter: null): CollectionReference; +withConverter(converter: null): CollectionReference; ``` ### Parameters @@ -115,7 +115,7 @@ withConverter(converter: null): CollectionReference; Returns: -[CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface)> +[CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface), [DocumentData](./firestore_.documentdata.md#documentdata_interface)> A `CollectionReference` that does not use a converter. diff --git a/docs-devsite/firestore_.documentchange.md b/docs-devsite/firestore_.documentchange.md index afef795956d..be65980dfc6 100644 --- a/docs-devsite/firestore_.documentchange.md +++ b/docs-devsite/firestore_.documentchange.md @@ -15,14 +15,14 @@ A `DocumentChange` represents a change to the documents matching a query. It con Signature: ```typescript -export declare interface DocumentChange +export declare interface DocumentChange ``` ## Properties | Property | Type | Description | | --- | --- | --- | -| [doc](./firestore_.documentchange.md#documentchangedoc) | [QueryDocumentSnapshot](./firestore_.querydocumentsnapshot.md#querydocumentsnapshot_class)<T> | The document affected by this change. | +| [doc](./firestore_.documentchange.md#documentchangedoc) | [QueryDocumentSnapshot](./firestore_.querydocumentsnapshot.md#querydocumentsnapshot_class)<AppModelType, DbModelType> | The document affected by this change. | | [newIndex](./firestore_.documentchange.md#documentchangenewindex) | number | The index of the changed document in the result set immediately after this DocumentChange (i.e. supposing that all prior DocumentChange objects and the current DocumentChange object have been applied). Is -1 for 'removed' events. | | [oldIndex](./firestore_.documentchange.md#documentchangeoldindex) | number | The index of the changed document in the result set immediately prior to this DocumentChange (i.e. supposing that all prior DocumentChange objects have been applied). Is -1 for 'added' events. | | [type](./firestore_.documentchange.md#documentchangetype) | [DocumentChangeType](./firestore_.md#documentchangetype) | The type of change ('added', 'modified', or 'removed'). | @@ -34,7 +34,7 @@ The document affected by this change. Signature: ```typescript -readonly doc: QueryDocumentSnapshot; +readonly doc: QueryDocumentSnapshot; ``` ## DocumentChange.newIndex diff --git a/docs-devsite/firestore_.documentreference.md b/docs-devsite/firestore_.documentreference.md index 16dff93b9c8..cc4d8ecc6b4 100644 --- a/docs-devsite/firestore_.documentreference.md +++ b/docs-devsite/firestore_.documentreference.md @@ -15,17 +15,17 @@ A `DocumentReference` refers to a document location in a Firestore database and Signature: ```typescript -export declare class DocumentReference +export declare class DocumentReference ``` ## Properties | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [converter](./firestore_.documentreference.md#documentreferenceconverter) | | [FirestoreDataConverter](./firestore_.firestoredataconverter.md#firestoredataconverter_interface)<T> \| null | If provided, the FirestoreDataConverter associated with this instance. | +| [converter](./firestore_.documentreference.md#documentreferenceconverter) | | [FirestoreDataConverter](./firestore_.firestoredataconverter.md#firestoredataconverter_interface)<AppModelType, DbModelType> \| null | If provided, the FirestoreDataConverter associated with this instance. | | [firestore](./firestore_.documentreference.md#documentreferencefirestore) | | [Firestore](./firestore_.firestore.md#firestore_class) | The [Firestore](./firestore_.firestore.md#firestore_class) instance the document is in. This is useful for performing transactions, for example. | | [id](./firestore_.documentreference.md#documentreferenceid) | | string | The document's identifier within its collection. | -| [parent](./firestore_.documentreference.md#documentreferenceparent) | | [CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<T> | The collection this DocumentReference belongs to. | +| [parent](./firestore_.documentreference.md#documentreferenceparent) | | [CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<AppModelType, DbModelType> | The collection this DocumentReference belongs to. | | [path](./firestore_.documentreference.md#documentreferencepath) | | string | A string representing the path of the referenced document (relative to the root of the database). | | [type](./firestore_.documentreference.md#documentreferencetype) | | (not declared) | The type of this Firestore reference. | @@ -43,7 +43,7 @@ If provided, the `FirestoreDataConverter` associated with this instance. Signature: ```typescript -readonly converter: FirestoreDataConverter | null; +readonly converter: FirestoreDataConverter | null; ``` ## DocumentReference.firestore @@ -73,7 +73,7 @@ The collection this `DocumentReference` belongs to. Signature: ```typescript -get parent(): CollectionReference; +get parent(): CollectionReference; ``` ## DocumentReference.path @@ -103,18 +103,18 @@ Applies a custom data converter to this `DocumentReference`, allowing yo Signature: ```typescript -withConverter(converter: FirestoreDataConverter): DocumentReference; +withConverter(converter: FirestoreDataConverter): DocumentReference; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| converter | [FirestoreDataConverter](./firestore_.firestoredataconverter.md#firestoredataconverter_interface)<U> | Converts objects to and from Firestore. | +| converter | [FirestoreDataConverter](./firestore_.firestoredataconverter.md#firestoredataconverter_interface)<NewAppModelType, NewDbModelType> | Converts objects to and from Firestore. | Returns: -[DocumentReference](./firestore_.documentreference.md#documentreference_class)<U> +[DocumentReference](./firestore_.documentreference.md#documentreference_class)<NewAppModelType, NewDbModelType> A `DocumentReference` that uses the provided converter. @@ -125,7 +125,7 @@ Removes the current converter. Signature: ```typescript -withConverter(converter: null): DocumentReference; +withConverter(converter: null): DocumentReference; ``` ### Parameters @@ -136,7 +136,7 @@ withConverter(converter: null): DocumentReference; Returns: -[DocumentReference](./firestore_.documentreference.md#documentreference_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface)> +[DocumentReference](./firestore_.documentreference.md#documentreference_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface), [DocumentData](./firestore_.documentdata.md#documentdata_interface)> A `DocumentReference` that does not use a converter. diff --git a/docs-devsite/firestore_.documentsnapshot.md b/docs-devsite/firestore_.documentsnapshot.md index 3ac2ec7dcb2..956d834b1ca 100644 --- a/docs-devsite/firestore_.documentsnapshot.md +++ b/docs-devsite/firestore_.documentsnapshot.md @@ -17,7 +17,7 @@ For a `DocumentSnapshot` that points to a non-existing document, any data access Signature: ```typescript -export declare class DocumentSnapshot +export declare class DocumentSnapshot ``` ## Constructors @@ -32,7 +32,7 @@ export declare class DocumentSnapshot | --- | --- | --- | --- | | [id](./firestore_.documentsnapshot.md#documentsnapshotid) | | string | Property of the DocumentSnapshot that provides the document's ID. | | [metadata](./firestore_.documentsnapshot.md#documentsnapshotmetadata) | | [SnapshotMetadata](./firestore_.snapshotmetadata.md#snapshotmetadata_class) | Metadata about the DocumentSnapshot, including information about its source and local modifications. | -| [ref](./firestore_.documentsnapshot.md#documentsnapshotref) | | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<T> | The DocumentReference for the document included in the DocumentSnapshot. | +| [ref](./firestore_.documentsnapshot.md#documentsnapshotref) | | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | The DocumentReference for the document included in the DocumentSnapshot. | ## Methods @@ -79,7 +79,7 @@ The `DocumentReference` for the document included in the `DocumentSnapshot`<T> +this is [QueryDocumentSnapshot](./firestore_.querydocumentsnapshot.md#querydocumentsnapshot_class)<AppModelType, DbModelType> ## DocumentSnapshot.get() diff --git a/docs-devsite/firestore_.firestoredataconverter.md b/docs-devsite/firestore_.firestoredataconverter.md index f7d80ac4a13..246c510e212 100644 --- a/docs-devsite/firestore_.firestoredataconverter.md +++ b/docs-devsite/firestore_.firestoredataconverter.md @@ -17,7 +17,7 @@ Using the converter allows you to specify generic type arguments when storing an Signature: ```typescript -export declare interface FirestoreDataConverter +export declare interface FirestoreDataConverter ``` ## Methods @@ -35,19 +35,19 @@ Called by the Firestore SDK to convert Firestore data into an object of type T. Signature: ```typescript -fromFirestore(snapshot: QueryDocumentSnapshot, options?: SnapshotOptions): T; +fromFirestore(snapshot: QueryDocumentSnapshot, options?: SnapshotOptions): AppModelType; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| snapshot | [QueryDocumentSnapshot](./firestore_.querydocumentsnapshot.md#querydocumentsnapshot_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface)> | A QueryDocumentSnapshot containing your data and metadata. | +| snapshot | [QueryDocumentSnapshot](./firestore_.querydocumentsnapshot.md#querydocumentsnapshot_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface), [DocumentData](./firestore_.documentdata.md#documentdata_interface)> | A QueryDocumentSnapshot containing your data and metadata. | | options | [SnapshotOptions](./firestore_.snapshotoptions.md#snapshotoptions_interface) | The SnapshotOptions from the initial call to data(). | Returns: -T +AppModelType ## FirestoreDataConverter.toFirestore() @@ -58,18 +58,18 @@ The `WithFieldValue` type extends `T` to also allow FieldValues such as [dele Signature: ```typescript -toFirestore(modelObject: WithFieldValue): DocumentData; +toFirestore(modelObject: WithFieldValue): WithFieldValue; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| modelObject | [WithFieldValue](./firestore_.md#withfieldvalue)<T> | | +| modelObject | [WithFieldValue](./firestore_.md#withfieldvalue)<AppModelType> | | Returns: -[DocumentData](./firestore_.documentdata.md#documentdata_interface) +[WithFieldValue](./firestore_.md#withfieldvalue)<DbModelType> ## FirestoreDataConverter.toFirestore() @@ -80,19 +80,19 @@ The `PartialWithFieldValue` type extends `Partial` to allow FieldValues su Signature: ```typescript -toFirestore(modelObject: PartialWithFieldValue, options: SetOptions): DocumentData; +toFirestore(modelObject: PartialWithFieldValue, options: SetOptions): PartialWithFieldValue; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| modelObject | [PartialWithFieldValue](./firestore_.md#partialwithfieldvalue)<T> | | +| modelObject | [PartialWithFieldValue](./firestore_.md#partialwithfieldvalue)<AppModelType> | | | options | [SetOptions](./firestore_.md#setoptions) | | Returns: -[DocumentData](./firestore_.documentdata.md#documentdata_interface) +[PartialWithFieldValue](./firestore_.md#partialwithfieldvalue)<DbModelType> ### Example diff --git a/docs-devsite/firestore_.md b/docs-devsite/firestore_.md index c38b6bb8407..9a386348a32 100644 --- a/docs-devsite/firestore_.md +++ b/docs-devsite/firestore_.md @@ -283,7 +283,7 @@ Gets a `CollectionReference` instance that refers to the collection at the speci Signature: ```typescript -export declare function collection(firestore: Firestore, path: string, ...pathSegments: string[]): CollectionReference; +export declare function collection(firestore: Firestore, path: string, ...pathSegments: string[]): CollectionReference; ``` ### Parameters @@ -296,7 +296,7 @@ export declare function collection(firestore: Firestore, path: string, ...pathSe Returns: -[CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface)> +[CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface), [DocumentData](./firestore_.documentdata.md#documentdata_interface)> The `CollectionReference` instance. @@ -311,7 +311,7 @@ Creates and returns a new `Query` instance that includes all documents in the da Signature: ```typescript -export declare function collectionGroup(firestore: Firestore, collectionId: string): Query; +export declare function collectionGroup(firestore: Firestore, collectionId: string): Query; ``` ### Parameters @@ -323,7 +323,7 @@ export declare function collectionGroup(firestore: Firestore, collectionId: stri Returns: -[Query](./firestore_.query.md#query_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface)> +[Query](./firestore_.query.md#query_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface), [DocumentData](./firestore_.documentdata.md#documentdata_interface)> The created `Query`. @@ -383,7 +383,7 @@ Gets a `DocumentReference` instance that refers to the document at the specified Signature: ```typescript -export declare function doc(firestore: Firestore, path: string, ...pathSegments: string[]): DocumentReference; +export declare function doc(firestore: Firestore, path: string, ...pathSegments: string[]): DocumentReference; ``` ### Parameters @@ -396,7 +396,7 @@ export declare function doc(firestore: Firestore, path: string, ...pathSegments: Returns: -[DocumentReference](./firestore_.documentreference.md#documentreference_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface)> +[DocumentReference](./firestore_.documentreference.md#documentreference_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface), [DocumentData](./firestore_.documentdata.md#documentdata_interface)> The `DocumentReference` instance. @@ -1043,15 +1043,15 @@ Two `AggregateQuerySnapshot` instances are considered "equal" if they have under Signature: ```typescript -export declare function aggregateQuerySnapshotEqual(left: AggregateQuerySnapshot, right: AggregateQuerySnapshot): boolean; +export declare function aggregateQuerySnapshotEqual(left: AggregateQuerySnapshot, right: AggregateQuerySnapshot): boolean; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| left | [AggregateQuerySnapshot](./firestore_.aggregatequerysnapshot.md#aggregatequerysnapshot_class)<T> | The first AggregateQuerySnapshot to compare. | -| right | [AggregateQuerySnapshot](./firestore_.aggregatequerysnapshot.md#aggregatequerysnapshot_class)<T> | The second AggregateQuerySnapshot to compare. | +| left | [AggregateQuerySnapshot](./firestore_.aggregatequerysnapshot.md#aggregatequerysnapshot_class)<AggregateSpecType, AppModelType, DbModelType> | The first AggregateQuerySnapshot to compare. | +| right | [AggregateQuerySnapshot](./firestore_.aggregatequerysnapshot.md#aggregatequerysnapshot_class)<AggregateSpecType, AppModelType, DbModelType> | The second AggregateQuerySnapshot to compare. | Returns: @@ -1066,15 +1066,15 @@ Returns true if the provided queries point to the same collection and apply the Signature: ```typescript -export declare function queryEqual(left: Query, right: Query): boolean; +export declare function queryEqual(left: Query, right: Query): boolean; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| left | [Query](./firestore_.query.md#query_class)<T> | A Query to compare. | -| right | [Query](./firestore_.query.md#query_class)<T> | A Query to compare. | +| left | [Query](./firestore_.query.md#query_class)<AppModelType, DbModelType> | A Query to compare. | +| right | [Query](./firestore_.query.md#query_class)<AppModelType, DbModelType> | A Query to compare. | Returns: @@ -1089,15 +1089,15 @@ Returns true if the provided references are equal. Signature: ```typescript -export declare function refEqual(left: DocumentReference | CollectionReference, right: DocumentReference | CollectionReference): boolean; +export declare function refEqual(left: DocumentReference | CollectionReference, right: DocumentReference | CollectionReference): boolean; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| left | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<T> \| [CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<T> | A reference to compare. | -| right | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<T> \| [CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<T> | A reference to compare. | +| left | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> \| [CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<AppModelType, DbModelType> | A reference to compare. | +| right | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> \| [CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<AppModelType, DbModelType> | A reference to compare. | Returns: @@ -1112,15 +1112,15 @@ Returns true if the provided snapshots are equal. Signature: ```typescript -export declare function snapshotEqual(left: DocumentSnapshot | QuerySnapshot, right: DocumentSnapshot | QuerySnapshot): boolean; +export declare function snapshotEqual(left: DocumentSnapshot | QuerySnapshot, right: DocumentSnapshot | QuerySnapshot): boolean; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| left | [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<T> \| [QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<T> | A snapshot to compare. | -| right | [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<T> \| [QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<T> | A snapshot to compare. | +| left | [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType> \| [QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<AppModelType, DbModelType> | A snapshot to compare. | +| right | [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType> \| [QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<AppModelType, DbModelType> | A snapshot to compare. | Returns: @@ -1231,20 +1231,20 @@ The result received from the server is presented, unaltered, without considering Signature: ```typescript -export declare function getCountFromServer(query: Query): Promise(query: Query): Promise; -}>>; +}, AppModelType, DbModelType>>; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| query | [Query](./firestore_.query.md#query_class)<unknown> | The query whose result set size to calculate. | +| query | [Query](./firestore_.query.md#query_class)<AppModelType, DbModelType> | The query whose result set size to calculate. | Returns: -Promise<[AggregateQuerySnapshot](./firestore_.aggregatequerysnapshot.md#aggregatequerysnapshot_class)<{ count: [AggregateField](./firestore_.aggregatefield.md#aggregatefield_class)<number>; }>> +Promise<[AggregateQuerySnapshot](./firestore_.aggregatequerysnapshot.md#aggregatequerysnapshot_class)<{ count: [AggregateField](./firestore_.aggregatefield.md#aggregatefield_class)<number>; }, AppModelType, DbModelType>> A Promise that will be resolved with the count; the count can be retrieved from `snapshot.data().count`, where `snapshot` is the `AggregateQuerySnapshot` to which the returned Promise resolves. @@ -1257,18 +1257,18 @@ Note: `getDocs()` attempts to provide up-to-date data when possible by waiting f Signature: ```typescript -export declare function getDocs(query: Query): Promise>; +export declare function getDocs(query: Query): Promise>; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| query | [Query](./firestore_.query.md#query_class)<T> | | +| query | [Query](./firestore_.query.md#query_class)<AppModelType, DbModelType> | | Returns: -Promise<[QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<T>> +Promise<[QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<AppModelType, DbModelType>> A `Promise` that will be resolved with the results of the query. @@ -1279,18 +1279,18 @@ Executes the query and returns the results as a `QuerySnapshot` from cache. Retu Signature: ```typescript -export declare function getDocsFromCache(query: Query): Promise>; +export declare function getDocsFromCache(query: Query): Promise>; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| query | [Query](./firestore_.query.md#query_class)<T> | | +| query | [Query](./firestore_.query.md#query_class)<AppModelType, DbModelType> | | Returns: -Promise<[QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<T>> +Promise<[QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<AppModelType, DbModelType>> A `Promise` that will be resolved with the results of the query. @@ -1301,18 +1301,18 @@ Executes the query and returns the results as a `QuerySnapshot` from the server. Signature: ```typescript -export declare function getDocsFromServer(query: Query): Promise>; +export declare function getDocsFromServer(query: Query): Promise>; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| query | [Query](./firestore_.query.md#query_class)<T> | | +| query | [Query](./firestore_.query.md#query_class)<AppModelType, DbModelType> | | Returns: -Promise<[QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<T>> +Promise<[QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<AppModelType, DbModelType>> A `Promise` that will be resolved with the results of the query. @@ -1325,8 +1325,8 @@ NOTE: Although an `onCompletion` callback can be provided, it will never be call Signature: ```typescript -export declare function onSnapshot(query: Query, observer: { - next?: (snapshot: QuerySnapshot) => void; +export declare function onSnapshot(query: Query, observer: { + next?: (snapshot: QuerySnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; }): Unsubscribe; @@ -1336,8 +1336,8 @@ export declare function onSnapshot(query: Query, observer: { | Parameter | Type | Description | | --- | --- | --- | -| query | [Query](./firestore_.query.md#query_class)<T> | The query to listen to. | -| observer | { next?: (snapshot: [QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<T>) => void; error?: (error: [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class)) => void; complete?: () => void; } | A single object containing next and error callbacks. | +| query | [Query](./firestore_.query.md#query_class)<AppModelType, DbModelType> | The query to listen to. | +| observer | { next?: (snapshot: [QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<AppModelType, DbModelType>) => void; error?: (error: [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class)) => void; complete?: () => void; } | A single object containing next and error callbacks. | Returns: @@ -1354,8 +1354,8 @@ NOTE: Although an `onCompletion` callback can be provided, it will never be call Signature: ```typescript -export declare function onSnapshot(query: Query, options: SnapshotListenOptions, observer: { - next?: (snapshot: QuerySnapshot) => void; +export declare function onSnapshot(query: Query, options: SnapshotListenOptions, observer: { + next?: (snapshot: QuerySnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; }): Unsubscribe; @@ -1365,9 +1365,9 @@ export declare function onSnapshot(query: Query, options: SnapshotListenOp | Parameter | Type | Description | | --- | --- | --- | -| query | [Query](./firestore_.query.md#query_class)<T> | The query to listen to. | +| query | [Query](./firestore_.query.md#query_class)<AppModelType, DbModelType> | The query to listen to. | | options | [SnapshotListenOptions](./firestore_.snapshotlistenoptions.md#snapshotlistenoptions_interface) | Options controlling the listen behavior. | -| observer | { next?: (snapshot: [QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<T>) => void; error?: (error: [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class)) => void; complete?: () => void; } | A single object containing next and error callbacks. | +| observer | { next?: (snapshot: [QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<AppModelType, DbModelType>) => void; error?: (error: [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class)) => void; complete?: () => void; } | A single object containing next and error callbacks. | Returns: @@ -1384,15 +1384,15 @@ NOTE: Although an `onCompletion` callback can be provided, it will never be call Signature: ```typescript -export declare function onSnapshot(query: Query, onNext: (snapshot: QuerySnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe; +export declare function onSnapshot(query: Query, onNext: (snapshot: QuerySnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| query | [Query](./firestore_.query.md#query_class)<T> | The query to listen to. | -| onNext | (snapshot: [QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<T>) => void | A callback to be called every time a new QuerySnapshot is available. | +| query | [Query](./firestore_.query.md#query_class)<AppModelType, DbModelType> | The query to listen to. | +| onNext | (snapshot: [QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<AppModelType, DbModelType>) => void | A callback to be called every time a new QuerySnapshot is available. | | onError | (error: [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class)) => void | A callback to be called if the listen fails or is cancelled. No further callbacks will occur. | | onCompletion | () => void | Can be provided, but will not be called since streams are never ending. | @@ -1411,16 +1411,16 @@ NOTE: Although an `onCompletion` callback can be provided, it will never be call Signature: ```typescript -export declare function onSnapshot(query: Query, options: SnapshotListenOptions, onNext: (snapshot: QuerySnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe; +export declare function onSnapshot(query: Query, options: SnapshotListenOptions, onNext: (snapshot: QuerySnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| query | [Query](./firestore_.query.md#query_class)<T> | The query to listen to. | +| query | [Query](./firestore_.query.md#query_class)<AppModelType, DbModelType> | The query to listen to. | | options | [SnapshotListenOptions](./firestore_.snapshotlistenoptions.md#snapshotlistenoptions_interface) | Options controlling the listen behavior. | -| onNext | (snapshot: [QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<T>) => void | A callback to be called every time a new QuerySnapshot is available. | +| onNext | (snapshot: [QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<AppModelType, DbModelType>) => void | A callback to be called every time a new QuerySnapshot is available. | | onError | (error: [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class)) => void | A callback to be called if the listen fails or is cancelled. No further callbacks will occur. | | onCompletion | () => void | Can be provided, but will not be called since streams are never ending. | @@ -1437,20 +1437,20 @@ Creates a new immutable instance of [Query](./firestore_.query.md#query_class) t Signature: ```typescript -export declare function query(query: Query, compositeFilter: QueryCompositeFilterConstraint, ...queryConstraints: QueryNonFilterConstraint[]): Query; +export declare function query(query: Query, compositeFilter: QueryCompositeFilterConstraint, ...queryConstraints: QueryNonFilterConstraint[]): Query; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| query | [Query](./firestore_.query.md#query_class)<T> | The [Query](./firestore_.query.md#query_class) instance to use as a base for the new constraints. | +| query | [Query](./firestore_.query.md#query_class)<AppModelType, DbModelType> | The [Query](./firestore_.query.md#query_class) instance to use as a base for the new constraints. | | compositeFilter | [QueryCompositeFilterConstraint](./firestore_.querycompositefilterconstraint.md#querycompositefilterconstraint_class) | The [QueryCompositeFilterConstraint](./firestore_.querycompositefilterconstraint.md#querycompositefilterconstraint_class) to apply. Create [QueryCompositeFilterConstraint](./firestore_.querycompositefilterconstraint.md#querycompositefilterconstraint_class) using [and()](./firestore_.md#and) or [or()](./firestore_.md#or). | | queryConstraints | [QueryNonFilterConstraint](./firestore_.md#querynonfilterconstraint)\[\] | Additional [QueryNonFilterConstraint](./firestore_.md#querynonfilterconstraint)s to apply (e.g. [orderBy()](./firestore_.md#orderby), [limit()](./firestore_.md#limit)). | Returns: -[Query](./firestore_.query.md#query_class)<T> +[Query](./firestore_.query.md#query_class)<AppModelType, DbModelType> ## Exceptions @@ -1463,19 +1463,19 @@ Creates a new immutable instance of [Query](./firestore_.query.md#query_class) t Signature: ```typescript -export declare function query(query: Query, ...queryConstraints: QueryConstraint[]): Query; +export declare function query(query: Query, ...queryConstraints: QueryConstraint[]): Query; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| query | [Query](./firestore_.query.md#query_class)<T> | The [Query](./firestore_.query.md#query_class) instance to use as a base for the new constraints. | +| query | [Query](./firestore_.query.md#query_class)<AppModelType, DbModelType> | The [Query](./firestore_.query.md#query_class) instance to use as a base for the new constraints. | | queryConstraints | [QueryConstraint](./firestore_.queryconstraint.md#queryconstraint_class)\[\] | The list of [QueryConstraint](./firestore_.queryconstraint.md#queryconstraint_class)s to apply. | Returns: -[Query](./firestore_.query.md#query_class)<T> +[Query](./firestore_.query.md#query_class)<AppModelType, DbModelType> ## Exceptions @@ -1532,19 +1532,19 @@ Add a new document to specified `CollectionReference` with the given data, assig Signature: ```typescript -export declare function addDoc(reference: CollectionReference, data: WithFieldValue): Promise>; +export declare function addDoc(reference: CollectionReference, data: WithFieldValue): Promise>; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<T> | A reference to the collection to add this document to. | -| data | [WithFieldValue](./firestore_.md#withfieldvalue)<T> | An Object containing the data for the new document. | +| reference | [CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<AppModelType, DbModelType> | A reference to the collection to add this document to. | +| data | [WithFieldValue](./firestore_.md#withfieldvalue)<AppModelType> | An Object containing the data for the new document. | Returns: -Promise<[DocumentReference](./firestore_.documentreference.md#documentreference_class)<T>> +Promise<[DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType>> A `Promise` resolved with a `DocumentReference` pointing to the newly created document after it has been written to the backend (Note that it won't resolve while you're offline). @@ -1555,20 +1555,20 @@ Gets a `CollectionReference` instance that refers to a subcollection of `referen Signature: ```typescript -export declare function collection(reference: CollectionReference, path: string, ...pathSegments: string[]): CollectionReference; +export declare function collection(reference: CollectionReference, path: string, ...pathSegments: string[]): CollectionReference; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<unknown> | A reference to a collection. | +| reference | [CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<AppModelType, DbModelType> | A reference to a collection. | | path | string | A slash-separated path to a collection. | | pathSegments | string\[\] | Additional path segments to apply relative to the first argument. | Returns: -[CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface)> +[CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface), [DocumentData](./firestore_.documentdata.md#documentdata_interface)> The `CollectionReference` instance. @@ -1583,20 +1583,20 @@ Gets a `CollectionReference` instance that refers to a subcollection of `referen Signature: ```typescript -export declare function collection(reference: DocumentReference, path: string, ...pathSegments: string[]): CollectionReference; +export declare function collection(reference: DocumentReference, path: string, ...pathSegments: string[]): CollectionReference; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class) | A reference to a Firestore document. | +| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to a Firestore document. | | path | string | A slash-separated path to a collection. | | pathSegments | string\[\] | Additional path segments that will be applied relative to the first argument. | Returns: -[CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface)> +[CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface), [DocumentData](./firestore_.documentdata.md#documentdata_interface)> The `CollectionReference` instance. @@ -1611,14 +1611,14 @@ Deletes the document referred to by the specified `DocumentReference`. Signature: ```typescript -export declare function deleteDoc(reference: DocumentReference): Promise; +export declare function deleteDoc(reference: DocumentReference): Promise; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<unknown> | A reference to the document to delete. | +| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to delete. | Returns: @@ -1633,20 +1633,20 @@ Gets a `DocumentReference` instance that refers to a document within `reference` Signature: ```typescript -export declare function doc(reference: CollectionReference, path?: string, ...pathSegments: string[]): DocumentReference; +export declare function doc(reference: CollectionReference, path?: string, ...pathSegments: string[]): DocumentReference; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<T> | A reference to a collection. | +| reference | [CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<AppModelType, DbModelType> | A reference to a collection. | | path | string | A slash-separated path to a document. Has to be omitted to use auto-genrated IDs. | | pathSegments | string\[\] | Additional path segments that will be applied relative to the first argument. | Returns: -[DocumentReference](./firestore_.documentreference.md#documentreference_class)<T> +[DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> The `DocumentReference` instance. @@ -1661,20 +1661,20 @@ Gets a `DocumentReference` instance that refers to a document within `reference` Signature: ```typescript -export declare function doc(reference: DocumentReference, path: string, ...pathSegments: string[]): DocumentReference; +export declare function doc(reference: DocumentReference, path: string, ...pathSegments: string[]): DocumentReference; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<unknown> | A reference to a Firestore document. | +| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to a Firestore document. | | path | string | A slash-separated path to a document. | | pathSegments | string\[\] | Additional path segments that will be applied relative to the first argument. | Returns: -[DocumentReference](./firestore_.documentreference.md#documentreference_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface)> +[DocumentReference](./firestore_.documentreference.md#documentreference_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface), [DocumentData](./firestore_.documentdata.md#documentdata_interface)> The `DocumentReference` instance. @@ -1691,18 +1691,18 @@ Note: `getDoc()` attempts to provide up-to-date data when possible by waiting fo Signature: ```typescript -export declare function getDoc(reference: DocumentReference): Promise>; +export declare function getDoc(reference: DocumentReference): Promise>; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<T> | The reference of the document to fetch. | +| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | The reference of the document to fetch. | Returns: -Promise<[DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<T>> +Promise<[DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType>> A Promise resolved with a `DocumentSnapshot` containing the current document contents. @@ -1713,18 +1713,18 @@ Reads the document referred to by this `DocumentReference` from cache. Returns a Signature: ```typescript -export declare function getDocFromCache(reference: DocumentReference): Promise>; +export declare function getDocFromCache(reference: DocumentReference): Promise>; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<T> | | +| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | | Returns: -Promise<[DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<T>> +Promise<[DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType>> A `Promise` resolved with a `DocumentSnapshot` containing the current document contents. @@ -1735,18 +1735,18 @@ Reads the document referred to by this `DocumentReference` from the server. Retu Signature: ```typescript -export declare function getDocFromServer(reference: DocumentReference): Promise>; +export declare function getDocFromServer(reference: DocumentReference): Promise>; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<T> | | +| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | | Returns: -Promise<[DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<T>> +Promise<[DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType>> A `Promise` resolved with a `DocumentSnapshot` containing the current document contents. @@ -1759,8 +1759,8 @@ NOTE: Although an `onCompletion` callback can be provided, it will never be call Signature: ```typescript -export declare function onSnapshot(reference: DocumentReference, observer: { - next?: (snapshot: DocumentSnapshot) => void; +export declare function onSnapshot(reference: DocumentReference, observer: { + next?: (snapshot: DocumentSnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; }): Unsubscribe; @@ -1770,8 +1770,8 @@ export declare function onSnapshot(reference: DocumentReference, observer: | Parameter | Type | Description | | --- | --- | --- | -| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<T> | A reference to the document to listen to. | -| observer | { next?: (snapshot: [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<T>) => void; error?: (error: [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class)) => void; complete?: () => void; } | A single object containing next and error callbacks. | +| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to listen to. | +| observer | { next?: (snapshot: [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType>) => void; error?: (error: [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class)) => void; complete?: () => void; } | A single object containing next and error callbacks. | Returns: @@ -1788,8 +1788,8 @@ NOTE: Although an `onCompletion` callback can be provided, it will never be call Signature: ```typescript -export declare function onSnapshot(reference: DocumentReference, options: SnapshotListenOptions, observer: { - next?: (snapshot: DocumentSnapshot) => void; +export declare function onSnapshot(reference: DocumentReference, options: SnapshotListenOptions, observer: { + next?: (snapshot: DocumentSnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; }): Unsubscribe; @@ -1799,9 +1799,9 @@ export declare function onSnapshot(reference: DocumentReference, options: | Parameter | Type | Description | | --- | --- | --- | -| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<T> | A reference to the document to listen to. | +| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to listen to. | | options | [SnapshotListenOptions](./firestore_.snapshotlistenoptions.md#snapshotlistenoptions_interface) | Options controlling the listen behavior. | -| observer | { next?: (snapshot: [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<T>) => void; error?: (error: [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class)) => void; complete?: () => void; } | A single object containing next and error callbacks. | +| observer | { next?: (snapshot: [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType>) => void; error?: (error: [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class)) => void; complete?: () => void; } | A single object containing next and error callbacks. | Returns: @@ -1818,15 +1818,15 @@ NOTE: Although an `onCompletion` callback can be provided, it will never be call Signature: ```typescript -export declare function onSnapshot(reference: DocumentReference, onNext: (snapshot: DocumentSnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe; +export declare function onSnapshot(reference: DocumentReference, onNext: (snapshot: DocumentSnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<T> | A reference to the document to listen to. | -| onNext | (snapshot: [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<T>) => void | A callback to be called every time a new DocumentSnapshot is available. | +| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to listen to. | +| onNext | (snapshot: [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType>) => void | A callback to be called every time a new DocumentSnapshot is available. | | onError | (error: [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class)) => void | A callback to be called if the listen fails or is cancelled. No further callbacks will occur. | | onCompletion | () => void | Can be provided, but will not be called since streams are never ending. | @@ -1845,16 +1845,16 @@ NOTE: Although an `onCompletion` callback can be provided, it will never be call Signature: ```typescript -export declare function onSnapshot(reference: DocumentReference, options: SnapshotListenOptions, onNext: (snapshot: DocumentSnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe; +export declare function onSnapshot(reference: DocumentReference, options: SnapshotListenOptions, onNext: (snapshot: DocumentSnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<T> | A reference to the document to listen to. | +| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to listen to. | | options | [SnapshotListenOptions](./firestore_.snapshotlistenoptions.md#snapshotlistenoptions_interface) | Options controlling the listen behavior. | -| onNext | (snapshot: [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<T>) => void | A callback to be called every time a new DocumentSnapshot is available. | +| onNext | (snapshot: [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType>) => void | A callback to be called every time a new DocumentSnapshot is available. | | onError | (error: [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class)) => void | A callback to be called if the listen fails or is cancelled. No further callbacks will occur. | | onCompletion | () => void | Can be provided, but will not be called since streams are never ending. | @@ -1871,15 +1871,15 @@ Writes to the document referred to by this `DocumentReference`. If the d Signature: ```typescript -export declare function setDoc(reference: DocumentReference, data: WithFieldValue): Promise; +export declare function setDoc(reference: DocumentReference, data: WithFieldValue): Promise; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<T> | A reference to the document to write. | -| data | [WithFieldValue](./firestore_.md#withfieldvalue)<T> | A map of the fields and values for the document. | +| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to write. | +| data | [WithFieldValue](./firestore_.md#withfieldvalue)<AppModelType> | A map of the fields and values for the document. | Returns: @@ -1894,15 +1894,15 @@ Writes to the document referred to by the specified `DocumentReference`. Signature: ```typescript -export declare function setDoc(reference: DocumentReference, data: PartialWithFieldValue, options: SetOptions): Promise; +export declare function setDoc(reference: DocumentReference, data: PartialWithFieldValue, options: SetOptions): Promise; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<T> | A reference to the document to write. | -| data | [PartialWithFieldValue](./firestore_.md#partialwithfieldvalue)<T> | A map of the fields and values for the document. | +| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to write. | +| data | [PartialWithFieldValue](./firestore_.md#partialwithfieldvalue)<AppModelType> | A map of the fields and values for the document. | | options | [SetOptions](./firestore_.md#setoptions) | An object to configure the set behavior. | Returns: @@ -1918,15 +1918,15 @@ Updates fields in the document referred to by the specified `DocumentReference`< Signature: ```typescript -export declare function updateDoc(reference: DocumentReference, data: UpdateData): Promise; +export declare function updateDoc(reference: DocumentReference, data: UpdateData): Promise; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<T> | A reference to the document to update. | -| data | [UpdateData](./firestore_.md#updatedata)<T> | An object containing the fields and values with which to update the document. Fields can contain dots to reference nested fields within the document. | +| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to update. | +| data | [UpdateData](./firestore_.md#updatedata)<DbModelType> | An object containing the fields and values with which to update the document. Fields can contain dots to reference nested fields within the document. | Returns: @@ -1943,14 +1943,14 @@ Nested fields can be updated by providing dot-separated field path strings or by Signature: ```typescript -export declare function updateDoc(reference: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): Promise; +export declare function updateDoc(reference: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): Promise; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<unknown> | A reference to the document to update. | +| reference | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to update. | | field | string \| [FieldPath](./firestore_.fieldpath.md#fieldpath_class) | The first field to update. | | value | unknown | The first value. | | moreFieldsAndValues | unknown\[\] | Additional key value pairs. | diff --git a/docs-devsite/firestore_.query.md b/docs-devsite/firestore_.query.md index 1961c2cc5f3..7e7cea4fb45 100644 --- a/docs-devsite/firestore_.query.md +++ b/docs-devsite/firestore_.query.md @@ -15,7 +15,7 @@ A `Query` refers to a query which you can read or listen to. You can also constr Signature: ```typescript -export declare class Query +export declare class Query ``` ## Constructors @@ -28,7 +28,7 @@ export declare class Query | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [converter](./firestore_.query.md#queryconverter) | | [FirestoreDataConverter](./firestore_.firestoredataconverter.md#firestoredataconverter_interface)<T> \| null | If provided, the FirestoreDataConverter associated with this instance. | +| [converter](./firestore_.query.md#queryconverter) | | [FirestoreDataConverter](./firestore_.firestoredataconverter.md#firestoredataconverter_interface)<AppModelType, DbModelType> \| null | If provided, the FirestoreDataConverter associated with this instance. | | [firestore](./firestore_.query.md#queryfirestore) | | [Firestore](./firestore_.firestore.md#firestore_class) | The Firestore instance for the Firestore database (useful for performing transactions, etc.). | | [type](./firestore_.query.md#querytype) | | 'query' \| 'collection' | The type of this Firestore reference. | @@ -56,7 +56,7 @@ If provided, the `FirestoreDataConverter` associated with this instance. Signature: ```typescript -readonly converter: FirestoreDataConverter | null; +readonly converter: FirestoreDataConverter | null; ``` ## Query.firestore @@ -86,7 +86,7 @@ Removes the current converter. Signature: ```typescript -withConverter(converter: null): Query; +withConverter(converter: null): Query; ``` ### Parameters @@ -97,7 +97,7 @@ withConverter(converter: null): Query; Returns: -[Query](./firestore_.query.md#query_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface)> +[Query](./firestore_.query.md#query_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface), [DocumentData](./firestore_.documentdata.md#documentdata_interface)> A `Query` that does not use a converter. @@ -108,18 +108,18 @@ Applies a custom data converter to this query, allowing you to use your own cust Signature: ```typescript -withConverter(converter: FirestoreDataConverter): Query; +withConverter(converter: FirestoreDataConverter): Query; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| converter | [FirestoreDataConverter](./firestore_.firestoredataconverter.md#firestoredataconverter_interface)<U> | Converts objects to and from Firestore. | +| converter | [FirestoreDataConverter](./firestore_.firestoredataconverter.md#firestoredataconverter_interface)<NewAppModelType, NewDbModelType> | Converts objects to and from Firestore. | Returns: -[Query](./firestore_.query.md#query_class)<U> +[Query](./firestore_.query.md#query_class)<NewAppModelType, NewDbModelType> A `Query` that uses the provided converter. diff --git a/docs-devsite/firestore_.querydocumentsnapshot.md b/docs-devsite/firestore_.querydocumentsnapshot.md index 0755a11915f..d4f71f2fb55 100644 --- a/docs-devsite/firestore_.querydocumentsnapshot.md +++ b/docs-devsite/firestore_.querydocumentsnapshot.md @@ -17,9 +17,9 @@ A `QueryDocumentSnapshot` offers the same API surface as a `DocumentSnapshot`Signature: ```typescript -export declare class QueryDocumentSnapshot extends DocumentSnapshot +export declare class QueryDocumentSnapshot extends DocumentSnapshot ``` -Extends: [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<T> +Extends: [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType> ## Methods @@ -37,7 +37,7 @@ By default, `serverTimestamp()` values that have not yet been set to their final ```typescript /** @override */ -data(options?: SnapshotOptions): T; +data(options?: SnapshotOptions): AppModelType; ``` ### Parameters @@ -48,7 +48,7 @@ data(options?: SnapshotOptions): T; Returns: -T +AppModelType An `Object` containing all fields in the document. diff --git a/docs-devsite/firestore_.querysnapshot.md b/docs-devsite/firestore_.querysnapshot.md index 0abb869c003..cc67c6336d6 100644 --- a/docs-devsite/firestore_.querysnapshot.md +++ b/docs-devsite/firestore_.querysnapshot.md @@ -15,17 +15,17 @@ A `QuerySnapshot` contains zero or more `DocumentSnapshot` objects representing Signature: ```typescript -export declare class QuerySnapshot +export declare class QuerySnapshot ``` ## Properties | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [docs](./firestore_.querysnapshot.md#querysnapshotdocs) | | Array<[QueryDocumentSnapshot](./firestore_.querydocumentsnapshot.md#querydocumentsnapshot_class)<T>> | An array of all the documents in the QuerySnapshot. | +| [docs](./firestore_.querysnapshot.md#querysnapshotdocs) | | Array<[QueryDocumentSnapshot](./firestore_.querydocumentsnapshot.md#querydocumentsnapshot_class)<AppModelType, DbModelType>> | An array of all the documents in the QuerySnapshot. | | [empty](./firestore_.querysnapshot.md#querysnapshotempty) | | boolean | True if there are no documents in the QuerySnapshot. | | [metadata](./firestore_.querysnapshot.md#querysnapshotmetadata) | | [SnapshotMetadata](./firestore_.snapshotmetadata.md#snapshotmetadata_class) | Metadata about this snapshot, concerning its source and if it has local modifications. | -| [query](./firestore_.querysnapshot.md#querysnapshotquery) | | [Query](./firestore_.query.md#query_class)<T> | The query on which you called get or onSnapshot in order to get this QuerySnapshot. | +| [query](./firestore_.querysnapshot.md#querysnapshotquery) | | [Query](./firestore_.query.md#query_class)<AppModelType, DbModelType> | The query on which you called get or onSnapshot in order to get this QuerySnapshot. | | [size](./firestore_.querysnapshot.md#querysnapshotsize) | | number | The number of documents in the QuerySnapshot. | ## Methods @@ -42,7 +42,7 @@ An array of all the documents in the `QuerySnapshot`. Signature: ```typescript -get docs(): Array>; +get docs(): Array>; ``` ## QuerySnapshot.empty @@ -72,7 +72,7 @@ The query on which you called `get` or `onSnapshot` in order to get this `QueryS Signature: ```typescript -readonly query: Query; +readonly query: Query; ``` ## QuerySnapshot.size @@ -92,7 +92,7 @@ Returns an array of the documents changes since the last snapshot. If this is th Signature: ```typescript -docChanges(options?: SnapshotListenOptions): Array>; +docChanges(options?: SnapshotListenOptions): Array>; ``` ### Parameters @@ -103,7 +103,7 @@ docChanges(options?: SnapshotListenOptions): Array>; Returns: -Array<[DocumentChange](./firestore_.documentchange.md#documentchange_interface)<T>> +Array<[DocumentChange](./firestore_.documentchange.md#documentchange_interface)<AppModelType, DbModelType>> ## QuerySnapshot.forEach() @@ -112,14 +112,14 @@ Enumerates all of the documents in the `QuerySnapshot`. Signature: ```typescript -forEach(callback: (result: QueryDocumentSnapshot) => void, thisArg?: unknown): void; +forEach(callback: (result: QueryDocumentSnapshot) => void, thisArg?: unknown): void; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| callback | (result: [QueryDocumentSnapshot](./firestore_.querydocumentsnapshot.md#querydocumentsnapshot_class)<T>) => void | A callback to be called with a QueryDocumentSnapshot for each document in the snapshot. | +| callback | (result: [QueryDocumentSnapshot](./firestore_.querydocumentsnapshot.md#querydocumentsnapshot_class)<AppModelType, DbModelType>) => void | A callback to be called with a QueryDocumentSnapshot for each document in the snapshot. | | thisArg | unknown | The this binding for the callback. | Returns: diff --git a/docs-devsite/firestore_.transaction.md b/docs-devsite/firestore_.transaction.md index 24f0690bea4..b25fa2acb84 100644 --- a/docs-devsite/firestore_.transaction.md +++ b/docs-devsite/firestore_.transaction.md @@ -38,14 +38,14 @@ Deletes the document referred to by the provided [DocumentReference](./firestore Signature: ```typescript -delete(documentRef: DocumentReference): this; +delete(documentRef: DocumentReference): this; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| documentRef | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<unknown> | A reference to the document to be deleted. | +| documentRef | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to be deleted. | Returns: @@ -60,18 +60,18 @@ Reads the document referenced by the provided [DocumentReference](./firestore_.d Signature: ```typescript -get(documentRef: DocumentReference): Promise>; +get(documentRef: DocumentReference): Promise>; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| documentRef | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<T> | A reference to the document to be read. | +| documentRef | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to be read. | Returns: -Promise<[DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<T>> +Promise<[DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType>> A `DocumentSnapshot` with the read data. @@ -82,15 +82,15 @@ Writes to the document referred to by the provided [DocumentReference](./firesto Signature: ```typescript -set(documentRef: DocumentReference, data: WithFieldValue): this; +set(documentRef: DocumentReference, data: WithFieldValue): this; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| documentRef | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<T> | A reference to the document to be set. | -| data | [WithFieldValue](./firestore_.md#withfieldvalue)<T> | An object of the fields and values for the document. | +| documentRef | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to be set. | +| data | [WithFieldValue](./firestore_.md#withfieldvalue)<AppModelType> | An object of the fields and values for the document. | Returns: @@ -109,15 +109,15 @@ Writes to the document referred to by the provided [DocumentReference](./firesto Signature: ```typescript -set(documentRef: DocumentReference, data: PartialWithFieldValue, options: SetOptions): this; +set(documentRef: DocumentReference, data: PartialWithFieldValue, options: SetOptions): this; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| documentRef | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<T> | A reference to the document to be set. | -| data | [PartialWithFieldValue](./firestore_.md#partialwithfieldvalue)<T> | An object of the fields and values for the document. | +| documentRef | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to be set. | +| data | [PartialWithFieldValue](./firestore_.md#partialwithfieldvalue)<AppModelType> | An object of the fields and values for the document. | | options | [SetOptions](./firestore_.md#setoptions) | An object to configure the set behavior. | Returns: @@ -137,15 +137,15 @@ Updates fields in the document referred to by the provided [DocumentReference](. Signature: ```typescript -update(documentRef: DocumentReference, data: UpdateData): this; +update(documentRef: DocumentReference, data: UpdateData): this; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| documentRef | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<T> | A reference to the document to be updated. | -| data | [UpdateData](./firestore_.md#updatedata)<T> | An object containing the fields and values with which to update the document. Fields can contain dots to reference nested fields within the document. | +| documentRef | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to be updated. | +| data | [UpdateData](./firestore_.md#updatedata)<DbModelType> | An object containing the fields and values with which to update the document. Fields can contain dots to reference nested fields within the document. | Returns: @@ -166,14 +166,14 @@ Nested fields can be updated by providing dot-separated field path strings or by Signature: ```typescript -update(documentRef: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): this; +update(documentRef: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): this; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| documentRef | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<unknown> | A reference to the document to be updated. | +| documentRef | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to be updated. | | field | string \| [FieldPath](./firestore_.fieldpath.md#fieldpath_class) | The first field to update. | | value | unknown | The first value. | | moreFieldsAndValues | unknown\[\] | Additional key/value pairs. | diff --git a/docs-devsite/firestore_.writebatch.md b/docs-devsite/firestore_.writebatch.md index 878cb66810a..7fce73d40ea 100644 --- a/docs-devsite/firestore_.writebatch.md +++ b/docs-devsite/firestore_.writebatch.md @@ -55,14 +55,14 @@ Deletes the document referred to by the provided [DocumentReference](./firestore Signature: ```typescript -delete(documentRef: DocumentReference): WriteBatch; +delete(documentRef: DocumentReference): WriteBatch; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| documentRef | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<unknown> | A reference to the document to be deleted. | +| documentRef | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to be deleted. | Returns: @@ -77,15 +77,15 @@ Writes to the document referred to by the provided [DocumentReference](./firesto Signature: ```typescript -set(documentRef: DocumentReference, data: WithFieldValue): WriteBatch; +set(documentRef: DocumentReference, data: WithFieldValue): WriteBatch; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| documentRef | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<T> | A reference to the document to be set. | -| data | [WithFieldValue](./firestore_.md#withfieldvalue)<T> | An object of the fields and values for the document. | +| documentRef | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to be set. | +| data | [WithFieldValue](./firestore_.md#withfieldvalue)<AppModelType> | An object of the fields and values for the document. | Returns: @@ -100,15 +100,15 @@ Writes to the document referred to by the provided [DocumentReference](./firesto Signature: ```typescript -set(documentRef: DocumentReference, data: PartialWithFieldValue, options: SetOptions): WriteBatch; +set(documentRef: DocumentReference, data: PartialWithFieldValue, options: SetOptions): WriteBatch; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| documentRef | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<T> | A reference to the document to be set. | -| data | [PartialWithFieldValue](./firestore_.md#partialwithfieldvalue)<T> | An object of the fields and values for the document. | +| documentRef | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to be set. | +| data | [PartialWithFieldValue](./firestore_.md#partialwithfieldvalue)<AppModelType> | An object of the fields and values for the document. | | options | [SetOptions](./firestore_.md#setoptions) | An object to configure the set behavior. | Returns: @@ -128,15 +128,15 @@ Updates fields in the document referred to by the provided [DocumentReference](. Signature: ```typescript -update(documentRef: DocumentReference, data: UpdateData): WriteBatch; +update(documentRef: DocumentReference, data: UpdateData): WriteBatch; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| documentRef | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<T> | A reference to the document to be updated. | -| data | [UpdateData](./firestore_.md#updatedata)<T> | An object containing the fields and values with which to update the document. Fields can contain dots to reference nested fields within the document. | +| documentRef | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to be updated. | +| data | [UpdateData](./firestore_.md#updatedata)<DbModelType> | An object containing the fields and values with which to update the document. Fields can contain dots to reference nested fields within the document. | Returns: @@ -157,14 +157,14 @@ Nested fields can be update by providing dot-separated field path strings or by Signature: ```typescript -update(documentRef: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): WriteBatch; +update(documentRef: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): WriteBatch; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| documentRef | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<unknown> | A reference to the document to be updated. | +| documentRef | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to be updated. | | field | string \| [FieldPath](./firestore_.fieldpath.md#fieldpath_class) | The first field to update. | | value | unknown | The first value. | | moreFieldsAndValues | unknown\[\] | Additional key value pairs. | diff --git a/docs-devsite/firestore_lite.aggregatequerysnapshot.md b/docs-devsite/firestore_lite.aggregatequerysnapshot.md index 4b5d3120ba3..3b9c5129be0 100644 --- a/docs-devsite/firestore_lite.aggregatequerysnapshot.md +++ b/docs-devsite/firestore_lite.aggregatequerysnapshot.md @@ -15,14 +15,14 @@ The results of executing an aggregation query. Signature: ```typescript -export declare class AggregateQuerySnapshot +export declare class AggregateQuerySnapshot ``` ## Properties | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [query](./firestore_lite.aggregatequerysnapshot.md#aggregatequerysnapshotquery) | | [Query](./firestore_lite.query.md#query_class)<unknown> | The underlying query over which the aggregations recorded in this AggregateQuerySnapshot were performed. | +| [query](./firestore_lite.aggregatequerysnapshot.md#aggregatequerysnapshotquery) | | [Query](./firestore_lite.query.md#query_class)<AppModelType, DbModelType> | The underlying query over which the aggregations recorded in this AggregateQuerySnapshot were performed. | | [type](./firestore_lite.aggregatequerysnapshot.md#aggregatequerysnapshottype) | | (not declared) | A type string to uniquely identify instances of this class. | ## Methods @@ -38,7 +38,7 @@ The underlying query over which the aggregations recorded in this `AggregateQuer Signature: ```typescript -readonly query: Query; +readonly query: Query; ``` ## AggregateQuerySnapshot.type @@ -60,11 +60,11 @@ The keys of the returned object will be the same as those of the `AggregateSpec` Signature: ```typescript -data(): AggregateSpecData; +data(): AggregateSpecData; ``` Returns: -[AggregateSpecData](./firestore_lite.md#aggregatespecdata)<T> +[AggregateSpecData](./firestore_lite.md#aggregatespecdata)<AggregateSpecType> The results of the aggregations performed over the underlying query. diff --git a/docs-devsite/firestore_lite.collectionreference.md b/docs-devsite/firestore_lite.collectionreference.md index d446560a02f..18e64e719eb 100644 --- a/docs-devsite/firestore_lite.collectionreference.md +++ b/docs-devsite/firestore_lite.collectionreference.md @@ -15,16 +15,16 @@ A `CollectionReference` object can be used for adding documents, getting documen Signature: ```typescript -export declare class CollectionReference extends Query +export declare class CollectionReference extends Query ``` -Extends: [Query](./firestore_lite.query.md#query_class)<T> +Extends: [Query](./firestore_lite.query.md#query_class)<AppModelType, DbModelType> ## Properties | Property | Modifiers | Type | Description | | --- | --- | --- | --- | | [id](./firestore_lite.collectionreference.md#collectionreferenceid) | | string | The collection's identifier. | -| [parent](./firestore_lite.collectionreference.md#collectionreferenceparent) | | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> \| null | A reference to the containing DocumentReference if this is a subcollection. If this isn't a subcollection, the reference is null. | +| [parent](./firestore_lite.collectionreference.md#collectionreferenceparent) | | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface), [DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> \| null | A reference to the containing DocumentReference if this is a subcollection. If this isn't a subcollection, the reference is null. | | [path](./firestore_lite.collectionreference.md#collectionreferencepath) | | string | A string representing the path of the referenced collection (relative to the root of the database). | | [type](./firestore_lite.collectionreference.md#collectionreferencetype) | | (not declared) | The type of this Firestore reference. | @@ -52,7 +52,7 @@ A reference to the containing `DocumentReference` if this is a subcollection. If Signature: ```typescript -get parent(): DocumentReference | null; +get parent(): DocumentReference | null; ``` ## CollectionReference.path @@ -82,18 +82,18 @@ Applies a custom data converter to this `CollectionReference`, allowing Signature: ```typescript -withConverter(converter: FirestoreDataConverter): CollectionReference; +withConverter(converter: FirestoreDataConverter): CollectionReference; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| converter | [FirestoreDataConverter](./firestore_lite.firestoredataconverter.md#firestoredataconverter_interface)<U> | Converts objects to and from Firestore. | +| converter | [FirestoreDataConverter](./firestore_lite.firestoredataconverter.md#firestoredataconverter_interface)<NewAppModelType, NewDbModelType> | Converts objects to and from Firestore. | Returns: -[CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<U> +[CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<NewAppModelType, NewDbModelType> A `CollectionReference` that uses the provided converter. @@ -104,7 +104,7 @@ Removes the current converter. Signature: ```typescript -withConverter(converter: null): CollectionReference; +withConverter(converter: null): CollectionReference; ``` ### Parameters @@ -115,7 +115,7 @@ withConverter(converter: null): CollectionReference; Returns: -[CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> +[CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface), [DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> A `CollectionReference` that does not use a converter. diff --git a/docs-devsite/firestore_lite.documentreference.md b/docs-devsite/firestore_lite.documentreference.md index 0e307435949..7c02494faf4 100644 --- a/docs-devsite/firestore_lite.documentreference.md +++ b/docs-devsite/firestore_lite.documentreference.md @@ -15,17 +15,17 @@ A `DocumentReference` refers to a document location in a Firestore database and Signature: ```typescript -export declare class DocumentReference +export declare class DocumentReference ``` ## Properties | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [converter](./firestore_lite.documentreference.md#documentreferenceconverter) | | [FirestoreDataConverter](./firestore_lite.firestoredataconverter.md#firestoredataconverter_interface)<T> \| null | If provided, the FirestoreDataConverter associated with this instance. | +| [converter](./firestore_lite.documentreference.md#documentreferenceconverter) | | [FirestoreDataConverter](./firestore_lite.firestoredataconverter.md#firestoredataconverter_interface)<AppModelType, DbModelType> \| null | If provided, the FirestoreDataConverter associated with this instance. | | [firestore](./firestore_lite.documentreference.md#documentreferencefirestore) | | [Firestore](./firestore_lite.firestore.md#firestore_class) | The [Firestore](./firestore_.firestore.md#firestore_class) instance the document is in. This is useful for performing transactions, for example. | | [id](./firestore_lite.documentreference.md#documentreferenceid) | | string | The document's identifier within its collection. | -| [parent](./firestore_lite.documentreference.md#documentreferenceparent) | | [CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<T> | The collection this DocumentReference belongs to. | +| [parent](./firestore_lite.documentreference.md#documentreferenceparent) | | [CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<AppModelType, DbModelType> | The collection this DocumentReference belongs to. | | [path](./firestore_lite.documentreference.md#documentreferencepath) | | string | A string representing the path of the referenced document (relative to the root of the database). | | [type](./firestore_lite.documentreference.md#documentreferencetype) | | (not declared) | The type of this Firestore reference. | @@ -43,7 +43,7 @@ If provided, the `FirestoreDataConverter` associated with this instance. Signature: ```typescript -readonly converter: FirestoreDataConverter | null; +readonly converter: FirestoreDataConverter | null; ``` ## DocumentReference.firestore @@ -73,7 +73,7 @@ The collection this `DocumentReference` belongs to. Signature: ```typescript -get parent(): CollectionReference; +get parent(): CollectionReference; ``` ## DocumentReference.path @@ -103,18 +103,18 @@ Applies a custom data converter to this `DocumentReference`, allowing yo Signature: ```typescript -withConverter(converter: FirestoreDataConverter): DocumentReference; +withConverter(converter: FirestoreDataConverter): DocumentReference; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| converter | [FirestoreDataConverter](./firestore_lite.firestoredataconverter.md#firestoredataconverter_interface)<U> | Converts objects to and from Firestore. | +| converter | [FirestoreDataConverter](./firestore_lite.firestoredataconverter.md#firestoredataconverter_interface)<NewAppModelType, NewDbModelType> | Converts objects to and from Firestore. | Returns: -[DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<U> +[DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<NewAppModelType, NewDbModelType> A `DocumentReference` that uses the provided converter. @@ -125,7 +125,7 @@ Removes the current converter. Signature: ```typescript -withConverter(converter: null): DocumentReference; +withConverter(converter: null): DocumentReference; ``` ### Parameters @@ -136,7 +136,7 @@ withConverter(converter: null): DocumentReference; Returns: -[DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> +[DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface), [DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> A `DocumentReference` that does not use a converter. diff --git a/docs-devsite/firestore_lite.documentsnapshot.md b/docs-devsite/firestore_lite.documentsnapshot.md index cfea1feb919..00b4b005c70 100644 --- a/docs-devsite/firestore_lite.documentsnapshot.md +++ b/docs-devsite/firestore_lite.documentsnapshot.md @@ -17,7 +17,7 @@ For a `DocumentSnapshot` that points to a non-existing document, any data access Signature: ```typescript -export declare class DocumentSnapshot +export declare class DocumentSnapshot ``` ## Constructors @@ -31,7 +31,7 @@ export declare class DocumentSnapshot | Property | Modifiers | Type | Description | | --- | --- | --- | --- | | [id](./firestore_lite.documentsnapshot.md#documentsnapshotid) | | string | Property of the DocumentSnapshot that provides the document's ID. | -| [ref](./firestore_lite.documentsnapshot.md#documentsnapshotref) | | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<T> | The DocumentReference for the document included in the DocumentSnapshot. | +| [ref](./firestore_lite.documentsnapshot.md#documentsnapshotref) | | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType> | The DocumentReference for the document included in the DocumentSnapshot. | ## Methods @@ -68,7 +68,7 @@ The `DocumentReference` for the document included in the `DocumentSnapshot`. Returns `undefined` Signature: ```typescript -data(): T | undefined; +data(): AppModelType | undefined; ``` Returns: -T \| undefined +AppModelType \| undefined An `Object` containing all fields in the document or `undefined` if the document doesn't exist. @@ -93,11 +93,11 @@ Signals whether or not the document at the snapshot's location exists. Signature: ```typescript -exists(): this is QueryDocumentSnapshot; +exists(): this is QueryDocumentSnapshot; ``` Returns: -this is [QueryDocumentSnapshot](./firestore_lite.querydocumentsnapshot.md#querydocumentsnapshot_class)<T> +this is [QueryDocumentSnapshot](./firestore_lite.querydocumentsnapshot.md#querydocumentsnapshot_class)<AppModelType, DbModelType> true if the document exists. diff --git a/docs-devsite/firestore_lite.firestoredataconverter.md b/docs-devsite/firestore_lite.firestoredataconverter.md index 00510e0c22b..e508471ecfa 100644 --- a/docs-devsite/firestore_lite.firestoredataconverter.md +++ b/docs-devsite/firestore_lite.firestoredataconverter.md @@ -17,7 +17,7 @@ Using the converter allows you to specify generic type arguments when storing an Signature: ```typescript -export declare interface FirestoreDataConverter +export declare interface FirestoreDataConverter ``` ## Methods @@ -35,18 +35,18 @@ Called by the Firestore SDK to convert Firestore data into an object of type T. Signature: ```typescript -fromFirestore(snapshot: QueryDocumentSnapshot): T; +fromFirestore(snapshot: QueryDocumentSnapshot): AppModelType; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| snapshot | [QueryDocumentSnapshot](./firestore_lite.querydocumentsnapshot.md#querydocumentsnapshot_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> | A QueryDocumentSnapshot containing your data and metadata. | +| snapshot | [QueryDocumentSnapshot](./firestore_lite.querydocumentsnapshot.md#querydocumentsnapshot_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface), [DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> | A QueryDocumentSnapshot containing your data and metadata. | Returns: -T +AppModelType ## FirestoreDataConverter.toFirestore() @@ -57,18 +57,18 @@ The `WithFieldValue` type extends `T` to also allow FieldValues such as [dele Signature: ```typescript -toFirestore(modelObject: WithFieldValue): DocumentData; +toFirestore(modelObject: WithFieldValue): WithFieldValue; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| modelObject | [WithFieldValue](./firestore_lite.md#withfieldvalue)<T> | | +| modelObject | [WithFieldValue](./firestore_lite.md#withfieldvalue)<AppModelType> | | Returns: -[DocumentData](./firestore_lite.documentdata.md#documentdata_interface) +[WithFieldValue](./firestore_lite.md#withfieldvalue)<DbModelType> ## FirestoreDataConverter.toFirestore() @@ -79,19 +79,19 @@ The `PartialWithFieldValue` type extends `Partial` to allow FieldValues su Signature: ```typescript -toFirestore(modelObject: PartialWithFieldValue, options: SetOptions): DocumentData; +toFirestore(modelObject: PartialWithFieldValue, options: SetOptions): PartialWithFieldValue; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| modelObject | [PartialWithFieldValue](./firestore_lite.md#partialwithfieldvalue)<T> | | +| modelObject | [PartialWithFieldValue](./firestore_lite.md#partialwithfieldvalue)<AppModelType> | | | options | [SetOptions](./firestore_lite.md#setoptions) | | Returns: -[DocumentData](./firestore_lite.documentdata.md#documentdata_interface) +[PartialWithFieldValue](./firestore_lite.md#partialwithfieldvalue)<DbModelType> ### Example diff --git a/docs-devsite/firestore_lite.md b/docs-devsite/firestore_lite.md index b0ec302e722..f4748a838cd 100644 --- a/docs-devsite/firestore_lite.md +++ b/docs-devsite/firestore_lite.md @@ -193,7 +193,7 @@ Gets a `CollectionReference` instance that refers to the collection at the speci Signature: ```typescript -export declare function collection(firestore: Firestore, path: string, ...pathSegments: string[]): CollectionReference; +export declare function collection(firestore: Firestore, path: string, ...pathSegments: string[]): CollectionReference; ``` ### Parameters @@ -206,7 +206,7 @@ export declare function collection(firestore: Firestore, path: string, ...pathSe Returns: -[CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> +[CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface), [DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> The `CollectionReference` instance. @@ -221,7 +221,7 @@ Creates and returns a new `Query` instance that includes all documents in the da Signature: ```typescript -export declare function collectionGroup(firestore: Firestore, collectionId: string): Query; +export declare function collectionGroup(firestore: Firestore, collectionId: string): Query; ``` ### Parameters @@ -233,7 +233,7 @@ export declare function collectionGroup(firestore: Firestore, collectionId: stri Returns: -[Query](./firestore_lite.query.md#query_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> +[Query](./firestore_lite.query.md#query_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface), [DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> The created `Query`. @@ -271,7 +271,7 @@ Gets a `DocumentReference` instance that refers to the document at the specified Signature: ```typescript -export declare function doc(firestore: Firestore, path: string, ...pathSegments: string[]): DocumentReference; +export declare function doc(firestore: Firestore, path: string, ...pathSegments: string[]): DocumentReference; ``` ### Parameters @@ -284,7 +284,7 @@ export declare function doc(firestore: Firestore, path: string, ...pathSegments: Returns: -[DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> +[DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface), [DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> The `DocumentReference` instance. @@ -614,15 +614,15 @@ Two `AggregateQuerySnapshot` instances are considered "equal" if they have under Signature: ```typescript -export declare function aggregateQuerySnapshotEqual(left: AggregateQuerySnapshot, right: AggregateQuerySnapshot): boolean; +export declare function aggregateQuerySnapshotEqual(left: AggregateQuerySnapshot, right: AggregateQuerySnapshot): boolean; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| left | [AggregateQuerySnapshot](./firestore_lite.aggregatequerysnapshot.md#aggregatequerysnapshot_class)<T> | The first AggregateQuerySnapshot to compare. | -| right | [AggregateQuerySnapshot](./firestore_lite.aggregatequerysnapshot.md#aggregatequerysnapshot_class)<T> | The second AggregateQuerySnapshot to compare. | +| left | [AggregateQuerySnapshot](./firestore_lite.aggregatequerysnapshot.md#aggregatequerysnapshot_class)<AggregateSpecType, AppModelType, DbModelType> | The first AggregateQuerySnapshot to compare. | +| right | [AggregateQuerySnapshot](./firestore_lite.aggregatequerysnapshot.md#aggregatequerysnapshot_class)<AggregateSpecType, AppModelType, DbModelType> | The second AggregateQuerySnapshot to compare. | Returns: @@ -637,15 +637,15 @@ Returns true if the provided queries point to the same collection and apply the Signature: ```typescript -export declare function queryEqual(left: Query, right: Query): boolean; +export declare function queryEqual(left: Query, right: Query): boolean; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| left | [Query](./firestore_lite.query.md#query_class)<T> | A Query to compare. | -| right | [Query](./firestore_lite.query.md#query_class)<T> | A Query to compare. | +| left | [Query](./firestore_lite.query.md#query_class)<AppModelType, DbModelType> | A Query to compare. | +| right | [Query](./firestore_lite.query.md#query_class)<AppModelType, DbModelType> | A Query to compare. | Returns: @@ -660,15 +660,15 @@ Returns true if the provided references are equal. Signature: ```typescript -export declare function refEqual(left: DocumentReference | CollectionReference, right: DocumentReference | CollectionReference): boolean; +export declare function refEqual(left: DocumentReference | CollectionReference, right: DocumentReference | CollectionReference): boolean; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| left | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<T> \| [CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<T> | A reference to compare. | -| right | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<T> \| [CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<T> | A reference to compare. | +| left | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType> \| [CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<AppModelType, DbModelType> | A reference to compare. | +| right | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType> \| [CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<AppModelType, DbModelType> | A reference to compare. | Returns: @@ -683,15 +683,15 @@ Returns true if the provided snapshots are equal. Signature: ```typescript -export declare function snapshotEqual(left: DocumentSnapshot | QuerySnapshot, right: DocumentSnapshot | QuerySnapshot): boolean; +export declare function snapshotEqual(left: DocumentSnapshot | QuerySnapshot, right: DocumentSnapshot | QuerySnapshot): boolean; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| left | [DocumentSnapshot](./firestore_lite.documentsnapshot.md#documentsnapshot_class)<T> \| [QuerySnapshot](./firestore_lite.querysnapshot.md#querysnapshot_class)<T> | A snapshot to compare. | -| right | [DocumentSnapshot](./firestore_lite.documentsnapshot.md#documentsnapshot_class)<T> \| [QuerySnapshot](./firestore_lite.querysnapshot.md#querysnapshot_class)<T> | A snapshot to compare. | +| left | [DocumentSnapshot](./firestore_lite.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType> \| [QuerySnapshot](./firestore_lite.querysnapshot.md#querysnapshot_class)<AppModelType, DbModelType> | A snapshot to compare. | +| right | [DocumentSnapshot](./firestore_lite.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType> \| [QuerySnapshot](./firestore_lite.querysnapshot.md#querysnapshot_class)<AppModelType, DbModelType> | A snapshot to compare. | Returns: @@ -800,20 +800,20 @@ Using this function to count the documents is efficient because only the final c Signature: ```typescript -export declare function getCount(query: Query): Promise(query: Query): Promise; -}>>; +}, AppModelType, DbModelType>>; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| query | [Query](./firestore_lite.query.md#query_class)<unknown> | The query whose result set size to calculate. | +| query | [Query](./firestore_lite.query.md#query_class)<AppModelType, DbModelType> | The query whose result set size to calculate. | Returns: -Promise<[AggregateQuerySnapshot](./firestore_lite.aggregatequerysnapshot.md#aggregatequerysnapshot_class)<{ count: [AggregateField](./firestore_lite.aggregatefield.md#aggregatefield_class)<number>; }>> +Promise<[AggregateQuerySnapshot](./firestore_lite.aggregatequerysnapshot.md#aggregatequerysnapshot_class)<{ count: [AggregateField](./firestore_lite.aggregatefield.md#aggregatefield_class)<number>; }, AppModelType, DbModelType>> A Promise that will be resolved with the count; the count can be retrieved from `snapshot.data().count`, where `snapshot` is the `AggregateQuerySnapshot` to which the returned Promise resolves. @@ -826,18 +826,18 @@ All queries are executed directly by the server, even if the the query was previ Signature: ```typescript -export declare function getDocs(query: Query): Promise>; +export declare function getDocs(query: Query): Promise>; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| query | [Query](./firestore_lite.query.md#query_class)<T> | The Query to execute. | +| query | [Query](./firestore_lite.query.md#query_class)<AppModelType, DbModelType> | The Query to execute. | Returns: -Promise<[QuerySnapshot](./firestore_lite.querysnapshot.md#querysnapshot_class)<T>> +Promise<[QuerySnapshot](./firestore_lite.querysnapshot.md#querysnapshot_class)<AppModelType, DbModelType>> A Promise that will be resolved with the results of the query. @@ -848,20 +848,20 @@ Creates a new immutable instance of [Query](./firestore_.query.md#query_class) t Signature: ```typescript -export declare function query(query: Query, compositeFilter: QueryCompositeFilterConstraint, ...queryConstraints: QueryNonFilterConstraint[]): Query; +export declare function query(query: Query, compositeFilter: QueryCompositeFilterConstraint, ...queryConstraints: QueryNonFilterConstraint[]): Query; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| query | [Query](./firestore_lite.query.md#query_class)<T> | The [Query](./firestore_.query.md#query_class) instance to use as a base for the new constraints. | +| query | [Query](./firestore_lite.query.md#query_class)<AppModelType, DbModelType> | The [Query](./firestore_.query.md#query_class) instance to use as a base for the new constraints. | | compositeFilter | [QueryCompositeFilterConstraint](./firestore_lite.querycompositefilterconstraint.md#querycompositefilterconstraint_class) | The [QueryCompositeFilterConstraint](./firestore_.querycompositefilterconstraint.md#querycompositefilterconstraint_class) to apply. Create [QueryCompositeFilterConstraint](./firestore_.querycompositefilterconstraint.md#querycompositefilterconstraint_class) using [and()](./firestore_.md#and) or [or()](./firestore_.md#or). | | queryConstraints | [QueryNonFilterConstraint](./firestore_lite.md#querynonfilterconstraint)\[\] | Additional [QueryNonFilterConstraint](./firestore_.md#querynonfilterconstraint)s to apply (e.g. [orderBy()](./firestore_.md#orderby), [limit()](./firestore_.md#limit)). | Returns: -[Query](./firestore_lite.query.md#query_class)<T> +[Query](./firestore_lite.query.md#query_class)<AppModelType, DbModelType> ## Exceptions @@ -874,19 +874,19 @@ Creates a new immutable instance of [Query](./firestore_.query.md#query_class) t Signature: ```typescript -export declare function query(query: Query, ...queryConstraints: QueryConstraint[]): Query; +export declare function query(query: Query, ...queryConstraints: QueryConstraint[]): Query; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| query | [Query](./firestore_lite.query.md#query_class)<T> | The [Query](./firestore_.query.md#query_class) instance to use as a base for the new constraints. | +| query | [Query](./firestore_lite.query.md#query_class)<AppModelType, DbModelType> | The [Query](./firestore_.query.md#query_class) instance to use as a base for the new constraints. | | queryConstraints | [QueryConstraint](./firestore_lite.queryconstraint.md#queryconstraint_class)\[\] | The list of [QueryConstraint](./firestore_.queryconstraint.md#queryconstraint_class)s to apply. | Returns: -[Query](./firestore_lite.query.md#query_class)<T> +[Query](./firestore_lite.query.md#query_class)<AppModelType, DbModelType> ## Exceptions @@ -945,19 +945,19 @@ The result of this write will only be reflected in document reads that occur aft Signature: ```typescript -export declare function addDoc(reference: CollectionReference, data: WithFieldValue): Promise>; +export declare function addDoc(reference: CollectionReference, data: WithFieldValue): Promise>; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<T> | A reference to the collection to add this document to. | -| data | [WithFieldValue](./firestore_lite.md#withfieldvalue)<T> | An Object containing the data for the new document. | +| reference | [CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<AppModelType, DbModelType> | A reference to the collection to add this document to. | +| data | [WithFieldValue](./firestore_lite.md#withfieldvalue)<AppModelType> | An Object containing the data for the new document. | Returns: -Promise<[DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<T>> +Promise<[DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType>> A `Promise` resolved with a `DocumentReference` pointing to the newly created document after it has been written to the backend. @@ -972,20 +972,20 @@ Gets a `CollectionReference` instance that refers to a subcollection of `referen Signature: ```typescript -export declare function collection(reference: CollectionReference, path: string, ...pathSegments: string[]): CollectionReference; +export declare function collection(reference: CollectionReference, path: string, ...pathSegments: string[]): CollectionReference; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<unknown> | A reference to a collection. | +| reference | [CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<AppModelType, DbModelType> | A reference to a collection. | | path | string | A slash-separated path to a collection. | | pathSegments | string\[\] | Additional path segments to apply relative to the first argument. | Returns: -[CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> +[CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface), [DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> The `CollectionReference` instance. @@ -1000,20 +1000,20 @@ Gets a `CollectionReference` instance that refers to a subcollection of `referen Signature: ```typescript -export declare function collection(reference: DocumentReference, path: string, ...pathSegments: string[]): CollectionReference; +export declare function collection(reference: DocumentReference, path: string, ...pathSegments: string[]): CollectionReference; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class) | A reference to a Firestore document. | +| reference | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to a Firestore document. | | path | string | A slash-separated path to a collection. | | pathSegments | string\[\] | Additional path segments that will be applied relative to the first argument. | Returns: -[CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> +[CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface), [DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> The `CollectionReference` instance. @@ -1030,14 +1030,14 @@ The deletion will only be reflected in document reads that occur after the retur Signature: ```typescript -export declare function deleteDoc(reference: DocumentReference): Promise; +export declare function deleteDoc(reference: DocumentReference): Promise; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<unknown> | A reference to the document to delete. | +| reference | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to delete. | Returns: @@ -1052,20 +1052,20 @@ Gets a `DocumentReference` instance that refers to a document within `reference` Signature: ```typescript -export declare function doc(reference: CollectionReference, path?: string, ...pathSegments: string[]): DocumentReference; +export declare function doc(reference: CollectionReference, path?: string, ...pathSegments: string[]): DocumentReference; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<T> | A reference to a collection. | +| reference | [CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<AppModelType, DbModelType> | A reference to a collection. | | path | string | A slash-separated path to a document. Has to be omitted to use auto-genrated IDs. | | pathSegments | string\[\] | Additional path segments that will be applied relative to the first argument. | Returns: -[DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<T> +[DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType> The `DocumentReference` instance. @@ -1080,20 +1080,20 @@ Gets a `DocumentReference` instance that refers to a document within `reference` Signature: ```typescript -export declare function doc(reference: DocumentReference, path: string, ...pathSegments: string[]): DocumentReference; +export declare function doc(reference: DocumentReference, path: string, ...pathSegments: string[]): DocumentReference; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<unknown> | A reference to a Firestore document. | +| reference | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to a Firestore document. | | path | string | A slash-separated path to a document. | | pathSegments | string\[\] | Additional path segments that will be applied relative to the first argument. | Returns: -[DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> +[DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface), [DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> The `DocumentReference` instance. @@ -1110,18 +1110,18 @@ All documents are directly fetched from the server, even if the document was pre Signature: ```typescript -export declare function getDoc(reference: DocumentReference): Promise>; +export declare function getDoc(reference: DocumentReference): Promise>; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<T> | The reference of the document to fetch. | +| reference | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType> | The reference of the document to fetch. | Returns: -Promise<[DocumentSnapshot](./firestore_lite.documentsnapshot.md#documentsnapshot_class)<T>> +Promise<[DocumentSnapshot](./firestore_lite.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType>> A Promise resolved with a `DocumentSnapshot` containing the current document contents. @@ -1134,15 +1134,15 @@ The result of this write will only be reflected in document reads that occur aft Signature: ```typescript -export declare function setDoc(reference: DocumentReference, data: WithFieldValue): Promise; +export declare function setDoc(reference: DocumentReference, data: WithFieldValue): Promise; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<T> | A reference to the document to write. | -| data | [WithFieldValue](./firestore_lite.md#withfieldvalue)<T> | A map of the fields and values for the document. | +| reference | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to write. | +| data | [WithFieldValue](./firestore_lite.md#withfieldvalue)<AppModelType> | A map of the fields and values for the document. | Returns: @@ -1163,15 +1163,15 @@ The result of this write will only be reflected in document reads that occur aft Signature: ```typescript -export declare function setDoc(reference: DocumentReference, data: PartialWithFieldValue, options: SetOptions): Promise; +export declare function setDoc(reference: DocumentReference, data: PartialWithFieldValue, options: SetOptions): Promise; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<T> | A reference to the document to write. | -| data | [PartialWithFieldValue](./firestore_lite.md#partialwithfieldvalue)<T> | A map of the fields and values for the document. | +| reference | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to write. | +| data | [PartialWithFieldValue](./firestore_lite.md#partialwithfieldvalue)<AppModelType> | A map of the fields and values for the document. | | options | [SetOptions](./firestore_lite.md#setoptions) | An object to configure the set behavior. | Returns: @@ -1193,15 +1193,15 @@ The result of this update will only be reflected in document reads that occur af Signature: ```typescript -export declare function updateDoc(reference: DocumentReference, data: UpdateData): Promise; +export declare function updateDoc(reference: DocumentReference, data: UpdateData): Promise; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<T> | A reference to the document to update. | -| data | [UpdateData](./firestore_lite.md#updatedata)<T> | An object containing the fields and values with which to update the document. Fields can contain dots to reference nested fields within the document. | +| reference | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to update. | +| data | [UpdateData](./firestore_lite.md#updatedata)<DbModelType> | An object containing the fields and values with which to update the document. Fields can contain dots to reference nested fields within the document. | Returns: @@ -1224,14 +1224,14 @@ The result of this update will only be reflected in document reads that occur af Signature: ```typescript -export declare function updateDoc(reference: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): Promise; +export declare function updateDoc(reference: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): Promise; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| reference | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<unknown> | A reference to the document to update. | +| reference | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to update. | | field | string \| [FieldPath](./firestore_lite.fieldpath.md#fieldpath_class) | The first field to update. | | value | unknown | The first value. | | moreFieldsAndValues | unknown\[\] | Additional key value pairs. | diff --git a/docs-devsite/firestore_lite.query.md b/docs-devsite/firestore_lite.query.md index f2eac7560dc..d3b72d1ed04 100644 --- a/docs-devsite/firestore_lite.query.md +++ b/docs-devsite/firestore_lite.query.md @@ -15,7 +15,7 @@ A `Query` refers to a query which you can read or listen to. You can also constr Signature: ```typescript -export declare class Query +export declare class Query ``` ## Constructors @@ -28,7 +28,7 @@ export declare class Query | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [converter](./firestore_lite.query.md#queryconverter) | | [FirestoreDataConverter](./firestore_lite.firestoredataconverter.md#firestoredataconverter_interface)<T> \| null | If provided, the FirestoreDataConverter associated with this instance. | +| [converter](./firestore_lite.query.md#queryconverter) | | [FirestoreDataConverter](./firestore_lite.firestoredataconverter.md#firestoredataconverter_interface)<AppModelType, DbModelType> \| null | If provided, the FirestoreDataConverter associated with this instance. | | [firestore](./firestore_lite.query.md#queryfirestore) | | [Firestore](./firestore_lite.firestore.md#firestore_class) | The Firestore instance for the Firestore database (useful for performing transactions, etc.). | | [type](./firestore_lite.query.md#querytype) | | 'query' \| 'collection' | The type of this Firestore reference. | @@ -56,7 +56,7 @@ If provided, the `FirestoreDataConverter` associated with this instance. Signature: ```typescript -readonly converter: FirestoreDataConverter | null; +readonly converter: FirestoreDataConverter | null; ``` ## Query.firestore @@ -86,7 +86,7 @@ Removes the current converter. Signature: ```typescript -withConverter(converter: null): Query; +withConverter(converter: null): Query; ``` ### Parameters @@ -97,7 +97,7 @@ withConverter(converter: null): Query; Returns: -[Query](./firestore_lite.query.md#query_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> +[Query](./firestore_lite.query.md#query_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface), [DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> A `Query` that does not use a converter. @@ -108,18 +108,18 @@ Applies a custom data converter to this query, allowing you to use your own cust Signature: ```typescript -withConverter(converter: FirestoreDataConverter): Query; +withConverter(converter: FirestoreDataConverter): Query; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| converter | [FirestoreDataConverter](./firestore_lite.firestoredataconverter.md#firestoredataconverter_interface)<U> | Converts objects to and from Firestore. | +| converter | [FirestoreDataConverter](./firestore_lite.firestoredataconverter.md#firestoredataconverter_interface)<NewAppModelType, NewDbModelType> | Converts objects to and from Firestore. | Returns: -[Query](./firestore_lite.query.md#query_class)<U> +[Query](./firestore_lite.query.md#query_class)<NewAppModelType, NewDbModelType> A `Query` that uses the provided converter. diff --git a/docs-devsite/firestore_lite.querydocumentsnapshot.md b/docs-devsite/firestore_lite.querydocumentsnapshot.md index 356d7ecaeed..14824fe3ffc 100644 --- a/docs-devsite/firestore_lite.querydocumentsnapshot.md +++ b/docs-devsite/firestore_lite.querydocumentsnapshot.md @@ -17,9 +17,9 @@ A `QueryDocumentSnapshot` offers the same API surface as a `DocumentSnapshot`Signature: ```typescript -export declare class QueryDocumentSnapshot extends DocumentSnapshot +export declare class QueryDocumentSnapshot extends DocumentSnapshot ``` -Extends: [DocumentSnapshot](./firestore_lite.documentsnapshot.md#documentsnapshot_class)<T> +Extends: [DocumentSnapshot](./firestore_lite.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType> ## Methods @@ -35,11 +35,11 @@ Retrieves all fields in the document as an `Object`. ```typescript /** @override */ -data(): T; +data(): AppModelType; ``` Returns: -T +AppModelType An `Object` containing all fields in the document. diff --git a/docs-devsite/firestore_lite.querysnapshot.md b/docs-devsite/firestore_lite.querysnapshot.md index 8e805af948d..61ea8fa3f87 100644 --- a/docs-devsite/firestore_lite.querysnapshot.md +++ b/docs-devsite/firestore_lite.querysnapshot.md @@ -15,16 +15,16 @@ A `QuerySnapshot` contains zero or more `DocumentSnapshot` objects representing Signature: ```typescript -export declare class QuerySnapshot +export declare class QuerySnapshot ``` ## Properties | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [docs](./firestore_lite.querysnapshot.md#querysnapshotdocs) | | Array<[QueryDocumentSnapshot](./firestore_lite.querydocumentsnapshot.md#querydocumentsnapshot_class)<T>> | An array of all the documents in the QuerySnapshot. | +| [docs](./firestore_lite.querysnapshot.md#querysnapshotdocs) | | Array<[QueryDocumentSnapshot](./firestore_lite.querydocumentsnapshot.md#querydocumentsnapshot_class)<AppModelType, DbModelType>> | An array of all the documents in the QuerySnapshot. | | [empty](./firestore_lite.querysnapshot.md#querysnapshotempty) | | boolean | True if there are no documents in the QuerySnapshot. | -| [query](./firestore_lite.querysnapshot.md#querysnapshotquery) | | [Query](./firestore_lite.query.md#query_class)<T> | The query on which you called [getDocs()](./firestore_.md#getdocs) in order to get this QuerySnapshot. | +| [query](./firestore_lite.querysnapshot.md#querysnapshotquery) | | [Query](./firestore_lite.query.md#query_class)<AppModelType, DbModelType> | The query on which you called [getDocs()](./firestore_.md#getdocs) in order to get this QuerySnapshot. | | [size](./firestore_lite.querysnapshot.md#querysnapshotsize) | | number | The number of documents in the QuerySnapshot. | ## Methods @@ -40,7 +40,7 @@ An array of all the documents in the `QuerySnapshot`. Signature: ```typescript -get docs(): Array>; +get docs(): Array>; ``` ## QuerySnapshot.empty @@ -60,7 +60,7 @@ The query on which you called [getDocs()](./firestore_.md#getdocs) in order to g Signature: ```typescript -readonly query: Query; +readonly query: Query; ``` ## QuerySnapshot.size @@ -80,14 +80,14 @@ Enumerates all of the documents in the `QuerySnapshot`. Signature: ```typescript -forEach(callback: (result: QueryDocumentSnapshot) => void, thisArg?: unknown): void; +forEach(callback: (result: QueryDocumentSnapshot) => void, thisArg?: unknown): void; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| callback | (result: [QueryDocumentSnapshot](./firestore_lite.querydocumentsnapshot.md#querydocumentsnapshot_class)<T>) => void | A callback to be called with a QueryDocumentSnapshot for each document in the snapshot. | +| callback | (result: [QueryDocumentSnapshot](./firestore_lite.querydocumentsnapshot.md#querydocumentsnapshot_class)<AppModelType, DbModelType>) => void | A callback to be called with a QueryDocumentSnapshot for each document in the snapshot. | | thisArg | unknown | The this binding for the callback. | Returns: diff --git a/docs-devsite/firestore_lite.transaction.md b/docs-devsite/firestore_lite.transaction.md index c643f08d66e..503c762553c 100644 --- a/docs-devsite/firestore_lite.transaction.md +++ b/docs-devsite/firestore_lite.transaction.md @@ -38,14 +38,14 @@ Deletes the document referred to by the provided [DocumentReference](./firestore Signature: ```typescript -delete(documentRef: DocumentReference): this; +delete(documentRef: DocumentReference): this; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| documentRef | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<unknown> | A reference to the document to be deleted. | +| documentRef | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to be deleted. | Returns: @@ -60,18 +60,18 @@ Reads the document referenced by the provided [DocumentReference](./firestore_.d Signature: ```typescript -get(documentRef: DocumentReference): Promise>; +get(documentRef: DocumentReference): Promise>; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| documentRef | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<T> | A reference to the document to be read. | +| documentRef | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to be read. | Returns: -Promise<[DocumentSnapshot](./firestore_lite.documentsnapshot.md#documentsnapshot_class)<T>> +Promise<[DocumentSnapshot](./firestore_lite.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType>> A `DocumentSnapshot` with the read data. @@ -82,15 +82,15 @@ Writes to the document referred to by the provided [DocumentReference](./firesto Signature: ```typescript -set(documentRef: DocumentReference, data: WithFieldValue): this; +set(documentRef: DocumentReference, data: WithFieldValue): this; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| documentRef | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<T> | A reference to the document to be set. | -| data | [WithFieldValue](./firestore_lite.md#withfieldvalue)<T> | An object of the fields and values for the document. | +| documentRef | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to be set. | +| data | [WithFieldValue](./firestore_lite.md#withfieldvalue)<AppModelType> | An object of the fields and values for the document. | Returns: @@ -109,15 +109,15 @@ Writes to the document referred to by the provided [DocumentReference](./firesto Signature: ```typescript -set(documentRef: DocumentReference, data: PartialWithFieldValue, options: SetOptions): this; +set(documentRef: DocumentReference, data: PartialWithFieldValue, options: SetOptions): this; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| documentRef | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<T> | A reference to the document to be set. | -| data | [PartialWithFieldValue](./firestore_lite.md#partialwithfieldvalue)<T> | An object of the fields and values for the document. | +| documentRef | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to be set. | +| data | [PartialWithFieldValue](./firestore_lite.md#partialwithfieldvalue)<AppModelType> | An object of the fields and values for the document. | | options | [SetOptions](./firestore_lite.md#setoptions) | An object to configure the set behavior. | Returns: @@ -137,15 +137,15 @@ Updates fields in the document referred to by the provided [DocumentReference](. Signature: ```typescript -update(documentRef: DocumentReference, data: UpdateData): this; +update(documentRef: DocumentReference, data: UpdateData): this; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| documentRef | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<T> | A reference to the document to be updated. | -| data | [UpdateData](./firestore_lite.md#updatedata)<T> | An object containing the fields and values with which to update the document. Fields can contain dots to reference nested fields within the document. | +| documentRef | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to be updated. | +| data | [UpdateData](./firestore_lite.md#updatedata)<DbModelType> | An object containing the fields and values with which to update the document. Fields can contain dots to reference nested fields within the document. | Returns: @@ -166,14 +166,14 @@ Nested fields can be updated by providing dot-separated field path strings or by Signature: ```typescript -update(documentRef: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): this; +update(documentRef: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): this; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| documentRef | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<unknown> | A reference to the document to be updated. | +| documentRef | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to be updated. | | field | string \| [FieldPath](./firestore_lite.fieldpath.md#fieldpath_class) | The first field to update. | | value | unknown | The first value. | | moreFieldsAndValues | unknown\[\] | Additional key/value pairs. | diff --git a/docs-devsite/firestore_lite.writebatch.md b/docs-devsite/firestore_lite.writebatch.md index 141a99e8585..f3b80a0250d 100644 --- a/docs-devsite/firestore_lite.writebatch.md +++ b/docs-devsite/firestore_lite.writebatch.md @@ -55,14 +55,14 @@ Deletes the document referred to by the provided [DocumentReference](./firestore Signature: ```typescript -delete(documentRef: DocumentReference): WriteBatch; +delete(documentRef: DocumentReference): WriteBatch; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| documentRef | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<unknown> | A reference to the document to be deleted. | +| documentRef | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to be deleted. | Returns: @@ -77,15 +77,15 @@ Writes to the document referred to by the provided [DocumentReference](./firesto Signature: ```typescript -set(documentRef: DocumentReference, data: WithFieldValue): WriteBatch; +set(documentRef: DocumentReference, data: WithFieldValue): WriteBatch; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| documentRef | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<T> | A reference to the document to be set. | -| data | [WithFieldValue](./firestore_lite.md#withfieldvalue)<T> | An object of the fields and values for the document. | +| documentRef | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to be set. | +| data | [WithFieldValue](./firestore_lite.md#withfieldvalue)<AppModelType> | An object of the fields and values for the document. | Returns: @@ -100,15 +100,15 @@ Writes to the document referred to by the provided [DocumentReference](./firesto Signature: ```typescript -set(documentRef: DocumentReference, data: PartialWithFieldValue, options: SetOptions): WriteBatch; +set(documentRef: DocumentReference, data: PartialWithFieldValue, options: SetOptions): WriteBatch; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| documentRef | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<T> | A reference to the document to be set. | -| data | [PartialWithFieldValue](./firestore_lite.md#partialwithfieldvalue)<T> | An object of the fields and values for the document. | +| documentRef | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to be set. | +| data | [PartialWithFieldValue](./firestore_lite.md#partialwithfieldvalue)<AppModelType> | An object of the fields and values for the document. | | options | [SetOptions](./firestore_lite.md#setoptions) | An object to configure the set behavior. | Returns: @@ -128,15 +128,15 @@ Updates fields in the document referred to by the provided [DocumentReference](. Signature: ```typescript -update(documentRef: DocumentReference, data: UpdateData): WriteBatch; +update(documentRef: DocumentReference, data: UpdateData): WriteBatch; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| documentRef | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<T> | A reference to the document to be updated. | -| data | [UpdateData](./firestore_lite.md#updatedata)<T> | An object containing the fields and values with which to update the document. Fields can contain dots to reference nested fields within the document. | +| documentRef | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to be updated. | +| data | [UpdateData](./firestore_lite.md#updatedata)<DbModelType> | An object containing the fields and values with which to update the document. Fields can contain dots to reference nested fields within the document. | Returns: @@ -157,14 +157,14 @@ Nested fields can be update by providing dot-separated field path strings or by Signature: ```typescript -update(documentRef: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): WriteBatch; +update(documentRef: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): WriteBatch; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| documentRef | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<unknown> | A reference to the document to be updated. | +| documentRef | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppModelType, DbModelType> | A reference to the document to be updated. | | field | string \| [FieldPath](./firestore_lite.fieldpath.md#fieldpath_class) | The first field to update. | | value | unknown | The first value. | | moreFieldsAndValues | unknown\[\] | Additional key value pairs. | From 4b5bbc5577512c9b21193a0e4ed82a870cfd6801 Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Fri, 19 May 2023 14:11:29 -0400 Subject: [PATCH 04/10] yarn changeset --- .changeset/rude-terms-remain.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/rude-terms-remain.md diff --git a/.changeset/rude-terms-remain.md b/.changeset/rude-terms-remain.md new file mode 100644 index 00000000000..61fbb80f829 --- /dev/null +++ b/.changeset/rude-terms-remain.md @@ -0,0 +1,6 @@ +--- +'@firebase/firestore': major +'firebase': major +--- + +Fixed updateDoc() typing issue by adding a 2nd type parameter to FirestoreDataConverter From 60dd1b4c45168ca7815abd57d486dca4e34f2677 Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Fri, 19 May 2023 14:57:13 -0400 Subject: [PATCH 05/10] Fix startAt, startAfter, endAt, endBefore --- common/api-review/firestore-lite.api.md | 8 +++--- common/api-review/firestore.api.md | 8 +++--- docs-devsite/firestore_.md | 16 ++++++------ docs-devsite/firestore_lite.md | 16 ++++++------ packages/firestore/src/lite-api/query.ts | 32 ++++++++++++------------ 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/common/api-review/firestore-lite.api.md b/common/api-review/firestore-lite.api.md index a1592cd14f3..dec76c665e4 100644 --- a/common/api-review/firestore-lite.api.md +++ b/common/api-review/firestore-lite.api.md @@ -143,13 +143,13 @@ export class DocumentSnapshot): QueryEndAtConstraint; +export function endAt(snapshot: DocumentSnapshot): QueryEndAtConstraint; // @public export function endAt(...fieldValues: unknown[]): QueryEndAtConstraint; // @public -export function endBefore(snapshot: DocumentSnapshot): QueryEndAtConstraint; +export function endBefore(snapshot: DocumentSnapshot): QueryEndAtConstraint; // @public export function endBefore(...fieldValues: unknown[]): QueryEndAtConstraint; @@ -368,13 +368,13 @@ export interface Settings { export function snapshotEqual(left: DocumentSnapshot | QuerySnapshot, right: DocumentSnapshot | QuerySnapshot): boolean; // @public -export function startAfter(snapshot: DocumentSnapshot): QueryStartAtConstraint; +export function startAfter(snapshot: DocumentSnapshot): QueryStartAtConstraint; // @public export function startAfter(...fieldValues: unknown[]): QueryStartAtConstraint; // @public -export function startAt(snapshot: DocumentSnapshot): QueryStartAtConstraint; +export function startAt(snapshot: DocumentSnapshot): QueryStartAtConstraint; // @public export function startAt(...fieldValues: unknown[]): QueryStartAtConstraint; diff --git a/common/api-review/firestore.api.md b/common/api-review/firestore.api.md index 3ab6a88cd74..12d2c9bb296 100644 --- a/common/api-review/firestore.api.md +++ b/common/api-review/firestore.api.md @@ -173,13 +173,13 @@ export function enableMultiTabIndexedDbPersistence(firestore: Firestore): Promis export function enableNetwork(firestore: Firestore): Promise; // @public -export function endAt(snapshot: DocumentSnapshot): QueryEndAtConstraint; +export function endAt(snapshot: DocumentSnapshot): QueryEndAtConstraint; // @public export function endAt(...fieldValues: unknown[]): QueryEndAtConstraint; // @public -export function endBefore(snapshot: DocumentSnapshot): QueryEndAtConstraint; +export function endBefore(snapshot: DocumentSnapshot): QueryEndAtConstraint; // @public export function endBefore(...fieldValues: unknown[]): QueryEndAtConstraint; @@ -627,13 +627,13 @@ export interface SnapshotOptions { } // @public -export function startAfter(snapshot: DocumentSnapshot): QueryStartAtConstraint; +export function startAfter(snapshot: DocumentSnapshot): QueryStartAtConstraint; // @public export function startAfter(...fieldValues: unknown[]): QueryStartAtConstraint; // @public -export function startAt(snapshot: DocumentSnapshot): QueryStartAtConstraint; +export function startAt(snapshot: DocumentSnapshot): QueryStartAtConstraint; // @public export function startAt(...fieldValues: unknown[]): QueryStartAtConstraint; diff --git a/docs-devsite/firestore_.md b/docs-devsite/firestore_.md index 9a386348a32..d700f9e7162 100644 --- a/docs-devsite/firestore_.md +++ b/docs-devsite/firestore_.md @@ -2052,14 +2052,14 @@ Creates a [QueryEndAtConstraint](./firestore_.queryendatconstraint.md#queryendat Signature: ```typescript -export declare function endAt(snapshot: DocumentSnapshot): QueryEndAtConstraint; +export declare function endAt(snapshot: DocumentSnapshot): QueryEndAtConstraint; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| snapshot | [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<unknown> | The snapshot of the document to end at. | +| snapshot | [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType> | The snapshot of the document to end at. | Returns: @@ -2074,14 +2074,14 @@ Creates a [QueryEndAtConstraint](./firestore_.queryendatconstraint.md#queryendat Signature: ```typescript -export declare function endBefore(snapshot: DocumentSnapshot): QueryEndAtConstraint; +export declare function endBefore(snapshot: DocumentSnapshot): QueryEndAtConstraint; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| snapshot | [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<unknown> | The snapshot of the document to end before. | +| snapshot | [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType> | The snapshot of the document to end before. | Returns: @@ -2096,14 +2096,14 @@ Creates a [QueryStartAtConstraint](./firestore_.querystartatconstraint.md#querys Signature: ```typescript -export declare function startAfter(snapshot: DocumentSnapshot): QueryStartAtConstraint; +export declare function startAfter(snapshot: DocumentSnapshot): QueryStartAtConstraint; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| snapshot | [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<unknown> | The snapshot of the document to start after. | +| snapshot | [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType> | The snapshot of the document to start after. | Returns: @@ -2118,14 +2118,14 @@ Creates a [QueryStartAtConstraint](./firestore_.querystartatconstraint.md#querys Signature: ```typescript -export declare function startAt(snapshot: DocumentSnapshot): QueryStartAtConstraint; +export declare function startAt(snapshot: DocumentSnapshot): QueryStartAtConstraint; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| snapshot | [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<unknown> | The snapshot of the document to start at. | +| snapshot | [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType> | The snapshot of the document to start at. | Returns: diff --git a/docs-devsite/firestore_lite.md b/docs-devsite/firestore_lite.md index f4748a838cd..26472b12b6c 100644 --- a/docs-devsite/firestore_lite.md +++ b/docs-devsite/firestore_lite.md @@ -1253,14 +1253,14 @@ Creates a [QueryEndAtConstraint](./firestore_.queryendatconstraint.md#queryendat Signature: ```typescript -export declare function endAt(snapshot: DocumentSnapshot): QueryEndAtConstraint; +export declare function endAt(snapshot: DocumentSnapshot): QueryEndAtConstraint; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| snapshot | [DocumentSnapshot](./firestore_lite.documentsnapshot.md#documentsnapshot_class)<unknown> | The snapshot of the document to end at. | +| snapshot | [DocumentSnapshot](./firestore_lite.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType> | The snapshot of the document to end at. | Returns: @@ -1275,14 +1275,14 @@ Creates a [QueryEndAtConstraint](./firestore_.queryendatconstraint.md#queryendat Signature: ```typescript -export declare function endBefore(snapshot: DocumentSnapshot): QueryEndAtConstraint; +export declare function endBefore(snapshot: DocumentSnapshot): QueryEndAtConstraint; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| snapshot | [DocumentSnapshot](./firestore_lite.documentsnapshot.md#documentsnapshot_class)<unknown> | The snapshot of the document to end before. | +| snapshot | [DocumentSnapshot](./firestore_lite.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType> | The snapshot of the document to end before. | Returns: @@ -1297,14 +1297,14 @@ Creates a [QueryStartAtConstraint](./firestore_.querystartatconstraint.md#querys Signature: ```typescript -export declare function startAfter(snapshot: DocumentSnapshot): QueryStartAtConstraint; +export declare function startAfter(snapshot: DocumentSnapshot): QueryStartAtConstraint; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| snapshot | [DocumentSnapshot](./firestore_lite.documentsnapshot.md#documentsnapshot_class)<unknown> | The snapshot of the document to start after. | +| snapshot | [DocumentSnapshot](./firestore_lite.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType> | The snapshot of the document to start after. | Returns: @@ -1319,14 +1319,14 @@ Creates a [QueryStartAtConstraint](./firestore_.querystartatconstraint.md#querys Signature: ```typescript -export declare function startAt(snapshot: DocumentSnapshot): QueryStartAtConstraint; +export declare function startAt(snapshot: DocumentSnapshot): QueryStartAtConstraint; ``` ### Parameters | Parameter | Type | Description | | --- | --- | --- | -| snapshot | [DocumentSnapshot](./firestore_lite.documentsnapshot.md#documentsnapshot_class)<unknown> | The snapshot of the document to start at. | +| snapshot | [DocumentSnapshot](./firestore_lite.documentsnapshot.md#documentsnapshot_class)<AppModelType, DbModelType> | The snapshot of the document to start at. | Returns: diff --git a/packages/firestore/src/lite-api/query.ts b/packages/firestore/src/lite-api/query.ts index cff35769845..617a60a4462 100644 --- a/packages/firestore/src/lite-api/query.ts +++ b/packages/firestore/src/lite-api/query.ts @@ -606,8 +606,8 @@ export class QueryStartAtConstraint extends QueryConstraint { * @param snapshot - The snapshot of the document to start at. * @returns A {@link QueryStartAtConstraint} to pass to `query()`. */ -export function startAt( - snapshot: DocumentSnapshot +export function startAt( + snapshot: DocumentSnapshot ): QueryStartAtConstraint; /** * Creates a {@link QueryStartAtConstraint} that modifies the result set to @@ -619,8 +619,8 @@ export function startAt( * @returns A {@link QueryStartAtConstraint} to pass to `query()`. */ export function startAt(...fieldValues: unknown[]): QueryStartAtConstraint; -export function startAt( - ...docOrFields: Array> +export function startAt( + ...docOrFields: Array> ): QueryStartAtConstraint { return QueryStartAtConstraint._create( 'startAt', @@ -638,8 +638,8 @@ export function startAt( * @param snapshot - The snapshot of the document to start after. * @returns A {@link QueryStartAtConstraint} to pass to `query()` */ -export function startAfter( - snapshot: DocumentSnapshot +export function startAfter( + snapshot: DocumentSnapshot ): QueryStartAtConstraint; /** * Creates a {@link QueryStartAtConstraint} that modifies the result set to @@ -651,8 +651,8 @@ export function startAfter( * @returns A {@link QueryStartAtConstraint} to pass to `query()` */ export function startAfter(...fieldValues: unknown[]): QueryStartAtConstraint; -export function startAfter( - ...docOrFields: Array> +export function startAfter( + ...docOrFields: Array> ): QueryStartAtConstraint { return QueryStartAtConstraint._create( 'startAfter', @@ -715,8 +715,8 @@ export class QueryEndAtConstraint extends QueryConstraint { * @param snapshot - The snapshot of the document to end before. * @returns A {@link QueryEndAtConstraint} to pass to `query()` */ -export function endBefore( - snapshot: DocumentSnapshot +export function endBefore( + snapshot: DocumentSnapshot ): QueryEndAtConstraint; /** * Creates a {@link QueryEndAtConstraint} that modifies the result set to end @@ -728,8 +728,8 @@ export function endBefore( * @returns A {@link QueryEndAtConstraint} to pass to `query()` */ export function endBefore(...fieldValues: unknown[]): QueryEndAtConstraint; -export function endBefore( - ...docOrFields: Array> +export function endBefore( + ...docOrFields: Array> ): QueryEndAtConstraint { return QueryEndAtConstraint._create( 'endBefore', @@ -747,8 +747,8 @@ export function endBefore( * @param snapshot - The snapshot of the document to end at. * @returns A {@link QueryEndAtConstraint} to pass to `query()` */ -export function endAt( - snapshot: DocumentSnapshot +export function endAt( + snapshot: DocumentSnapshot ): QueryEndAtConstraint; /** * Creates a {@link QueryEndAtConstraint} that modifies the result set to end at @@ -760,8 +760,8 @@ export function endAt( * @returns A {@link QueryEndAtConstraint} to pass to `query()` */ export function endAt(...fieldValues: unknown[]): QueryEndAtConstraint; -export function endAt( - ...docOrFields: Array> +export function endAt( + ...docOrFields: Array> ): QueryEndAtConstraint { return QueryEndAtConstraint._create( 'endAt', From 1ddf0bdc0be506512acfa9c24df2ae47826921eb Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Fri, 19 May 2023 15:15:20 -0400 Subject: [PATCH 06/10] firestore_client.ts: removed unused imports --- packages/firestore/src/core/firestore_client.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/firestore/src/core/firestore_client.ts b/packages/firestore/src/core/firestore_client.ts index 595cdb0ca01..df6127f978e 100644 --- a/packages/firestore/src/core/firestore_client.ts +++ b/packages/firestore/src/core/firestore_client.ts @@ -91,8 +91,6 @@ import { TransactionOptions } from './transaction_options'; import { TransactionRunner } from './transaction_runner'; import { View } from './view'; import { ViewSnapshot } from './view_snapshot'; -import { AggregateSpec } from '../lite-api/aggregate_types'; -import { DocumentData } from '../lite-api/reference'; const LOG_TAG = 'FirestoreClient'; export const MAX_CONCURRENT_LIMBO_RESOLUTIONS = 100; From 41b8a5af4ab62474d923221ecc0db024594cc015 Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Thu, 25 May 2023 14:37:30 -0700 Subject: [PATCH 07/10] add unit tests for v9 data converter uses --- .../test/unit/lite-api/types.test.ts | 185 ++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 packages/firestore/test/unit/lite-api/types.test.ts diff --git a/packages/firestore/test/unit/lite-api/types.test.ts b/packages/firestore/test/unit/lite-api/types.test.ts new file mode 100644 index 00000000000..5facffb89f1 --- /dev/null +++ b/packages/firestore/test/unit/lite-api/types.test.ts @@ -0,0 +1,185 @@ +/** + * @license + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0x00 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0x00 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { expect } from 'chai'; + +import { + DocumentData, + DocumentReference, + WithFieldValue, + PartialWithFieldValue, + SetOptions +} from '../../../src/lite-api/reference'; +import { + getDoc, + setDoc, + updateDoc +} from '../../../src/lite-api/reference_impl'; +import { + FirestoreDataConverter, + QueryDocumentSnapshot +} from '../../../src/lite-api/snapshot'; + +describe('FirestoreTypeConverter', () => { + it('converter has the minimal typing information', () => { + interface MyModelType { + stringProperty: string; + numberProperty: number; + } + const converter = { + toFirestore(obj: MyModelType) { + return { a: obj.stringProperty, b: obj.numberProperty }; + }, + fromFirestore(snapshot: QueryDocumentSnapshot) { + return { + stringProperty: snapshot.data().a, + numberProperty: snapshot.data().b + }; + } + }; + async function foo(docRef: DocumentReference): Promise { + const newDocRef = docRef.withConverter(converter); + await setDoc(newDocRef, { stringProperty: 'foo', numberProperty: 42 }); + const snapshot = await getDoc(newDocRef); + const data: MyModelType = snapshot.data()!; + expect(data.stringProperty).to.equal('foo'); + expect(data.numberProperty).to.equal(42); + } + }); + + it('converter has the minimal typing information plus return types', () => { + interface MyModelType { + stringProperty: string; + numberProperty: number; + } + const converter = { + toFirestore(obj: WithFieldValue): DocumentData { + return { a: obj.stringProperty, b: obj.numberProperty }; + }, + fromFirestore(snapshot: QueryDocumentSnapshot): MyModelType { + return { + stringProperty: snapshot.data().a, + numberProperty: snapshot.data().b + }; + } + }; + async function foo(docRef: DocumentReference): Promise { + const newDocRef = docRef.withConverter(converter); + await setDoc(newDocRef, { stringProperty: 'foo', numberProperty: 42 }); + const snapshot = await getDoc(newDocRef); + const data: MyModelType = snapshot.data()!; + expect(data.stringProperty).to.equal('foo'); + expect(data.numberProperty).to.equal(42); + } + }); + + it("has the additional 'merge' version of toFirestore()", () => { + interface MyModelType { + stringProperty: string; + numberProperty: number; + } + const converter = { + toFirestore( + modelObject: PartialWithFieldValue, + options?: SetOptions + ): DocumentData { + if (options === undefined) { + return { + a: modelObject.stringProperty, + b: modelObject.numberProperty + }; + } + const result: DocumentData = {}; + if ('stringProperty' in modelObject) { + result.a = modelObject.stringProperty; + } + if ('numberProperty' in modelObject) { + result.b = modelObject.numberProperty; + } + return result; + }, + fromFirestore(snapshot: QueryDocumentSnapshot): MyModelType { + return { + stringProperty: snapshot.data().a, + numberProperty: snapshot.data().b + }; + } + }; + async function foo(docRef: DocumentReference): Promise { + const newDocRef = docRef.withConverter(converter); + await setDoc(newDocRef, { stringProperty: 'foo', numberProperty: 42 }); + const snapshot = await getDoc(newDocRef); + const data: MyModelType = snapshot.data()!; + expect(data.stringProperty).to.equal('foo'); + expect(data.numberProperty).to.equal(42); + } + }); + + it('converter is explicitly typed as FirestoreDataConverter', () => { + interface MyModelType { + stringProperty: string; + numberProperty: number; + } + const converter: FirestoreDataConverter = { + toFirestore(obj: WithFieldValue) { + return { a: obj.stringProperty, b: obj.numberProperty }; + }, + fromFirestore(snapshot: QueryDocumentSnapshot) { + return { + stringProperty: snapshot.data().a, + numberProperty: snapshot.data().b + }; + } + }; + async function foo(docRef: DocumentReference): Promise { + const newDocRef = docRef.withConverter(converter); + await setDoc(newDocRef, { stringProperty: 'foo', numberProperty: 42 }); + const snapshot = await getDoc(newDocRef); + const data: MyModelType = snapshot.data()!; + expect(data.stringProperty).to.equal('foo'); + expect(data.numberProperty).to.equal(42); + } + }); + + it('updateDoc() is typed incorrectly', () => { + interface MyModelType { + stringProperty: string; + numberProperty: number; + } + const converter: FirestoreDataConverter = { + toFirestore(obj: WithFieldValue) { + return { a: obj.stringProperty, b: obj.numberProperty }; + }, + fromFirestore(snapshot: QueryDocumentSnapshot) { + return { + stringProperty: snapshot.data().a, + numberProperty: snapshot.data().b + }; + } + }; + async function foo(docRef: DocumentReference): Promise { + const newDocRef = docRef.withConverter(converter); + // TODO(dconeybe) Update this test in the fix + // https://github.com/firebase/firebase-js-sdk/pull/7310 + // @ts-expect-error + await updateDoc(newDocRef, { a: 'newFoo', b: 43 }); + const snapshot = await getDoc(newDocRef); + const data: MyModelType = snapshot.data()!; + expect(data.stringProperty).to.be.a('string'); + expect(data.numberProperty).to.be.a('number'); + } + }); +}); From fe55b46a71d103aaecc978f3c32372157aee9ba7 Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Thu, 25 May 2023 15:04:13 -0700 Subject: [PATCH 08/10] update lite-api/types.test.ts for new type parameter --- .../test/unit/lite-api/types.test.ts | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/packages/firestore/test/unit/lite-api/types.test.ts b/packages/firestore/test/unit/lite-api/types.test.ts index 5facffb89f1..59e5370effe 100644 --- a/packages/firestore/test/unit/lite-api/types.test.ts +++ b/packages/firestore/test/unit/lite-api/types.test.ts @@ -53,10 +53,11 @@ describe('FirestoreTypeConverter', () => { async function foo(docRef: DocumentReference): Promise { const newDocRef = docRef.withConverter(converter); await setDoc(newDocRef, { stringProperty: 'foo', numberProperty: 42 }); + await updateDoc(newDocRef, { a: 'newFoo', b: 43 }); const snapshot = await getDoc(newDocRef); const data: MyModelType = snapshot.data()!; - expect(data.stringProperty).to.equal('foo'); - expect(data.numberProperty).to.equal(42); + expect(data.stringProperty).to.equal('newFoo'); + expect(data.numberProperty).to.equal(43); } }); @@ -79,10 +80,11 @@ describe('FirestoreTypeConverter', () => { async function foo(docRef: DocumentReference): Promise { const newDocRef = docRef.withConverter(converter); await setDoc(newDocRef, { stringProperty: 'foo', numberProperty: 42 }); + await updateDoc(newDocRef, { a: 'newFoo', b: 43 }); const snapshot = await getDoc(newDocRef); const data: MyModelType = snapshot.data()!; - expect(data.stringProperty).to.equal('foo'); - expect(data.numberProperty).to.equal(42); + expect(data.stringProperty).to.equal('newFoo'); + expect(data.numberProperty).to.equal(43); } }); @@ -121,10 +123,11 @@ describe('FirestoreTypeConverter', () => { async function foo(docRef: DocumentReference): Promise { const newDocRef = docRef.withConverter(converter); await setDoc(newDocRef, { stringProperty: 'foo', numberProperty: 42 }); + await updateDoc(newDocRef, { a: 'newFoo', b: 43 }); const snapshot = await getDoc(newDocRef); const data: MyModelType = snapshot.data()!; - expect(data.stringProperty).to.equal('foo'); - expect(data.numberProperty).to.equal(42); + expect(data.stringProperty).to.equal('newFoo'); + expect(data.numberProperty).to.equal(43); } }); @@ -147,19 +150,24 @@ describe('FirestoreTypeConverter', () => { async function foo(docRef: DocumentReference): Promise { const newDocRef = docRef.withConverter(converter); await setDoc(newDocRef, { stringProperty: 'foo', numberProperty: 42 }); + await updateDoc(newDocRef, { a: 'newFoo', b: 43 }); const snapshot = await getDoc(newDocRef); const data: MyModelType = snapshot.data()!; - expect(data.stringProperty).to.equal('foo'); - expect(data.numberProperty).to.equal(42); + expect(data.stringProperty).to.equal('newFoo'); + expect(data.numberProperty).to.equal(43); } }); - it('updateDoc() is typed incorrectly', () => { + it('converter is explicitly typed as FirestoreDataConverter', () => { interface MyModelType { stringProperty: string; numberProperty: number; } - const converter: FirestoreDataConverter = { + interface MyDbType { + a: string; + b: number; + } + const converter: FirestoreDataConverter = { toFirestore(obj: WithFieldValue) { return { a: obj.stringProperty, b: obj.numberProperty }; }, @@ -172,14 +180,12 @@ describe('FirestoreTypeConverter', () => { }; async function foo(docRef: DocumentReference): Promise { const newDocRef = docRef.withConverter(converter); - // TODO(dconeybe) Update this test in the fix - // https://github.com/firebase/firebase-js-sdk/pull/7310 - // @ts-expect-error + await setDoc(newDocRef, { stringProperty: 'foo', numberProperty: 42 }); await updateDoc(newDocRef, { a: 'newFoo', b: 43 }); const snapshot = await getDoc(newDocRef); const data: MyModelType = snapshot.data()!; - expect(data.stringProperty).to.be.a('string'); - expect(data.numberProperty).to.be.a('number'); + expect(data.stringProperty).to.equal('newFoo'); + expect(data.numberProperty).to.equal(43); } }); }); From a79cbea55e3c21a8a87fba8b8fc8602b53b01c01 Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Thu, 25 May 2023 15:31:02 -0700 Subject: [PATCH 09/10] lite-api/types.test.ts: fix error: 'foo' is defined but never used --- packages/firestore/test/unit/lite-api/types.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/firestore/test/unit/lite-api/types.test.ts b/packages/firestore/test/unit/lite-api/types.test.ts index 59e5370effe..0c51193e19e 100644 --- a/packages/firestore/test/unit/lite-api/types.test.ts +++ b/packages/firestore/test/unit/lite-api/types.test.ts @@ -50,7 +50,7 @@ describe('FirestoreTypeConverter', () => { }; } }; - async function foo(docRef: DocumentReference): Promise { + async function _(docRef: DocumentReference): Promise { const newDocRef = docRef.withConverter(converter); await setDoc(newDocRef, { stringProperty: 'foo', numberProperty: 42 }); await updateDoc(newDocRef, { a: 'newFoo', b: 43 }); @@ -77,7 +77,7 @@ describe('FirestoreTypeConverter', () => { }; } }; - async function foo(docRef: DocumentReference): Promise { + async function _(docRef: DocumentReference): Promise { const newDocRef = docRef.withConverter(converter); await setDoc(newDocRef, { stringProperty: 'foo', numberProperty: 42 }); await updateDoc(newDocRef, { a: 'newFoo', b: 43 }); @@ -120,7 +120,7 @@ describe('FirestoreTypeConverter', () => { }; } }; - async function foo(docRef: DocumentReference): Promise { + async function _(docRef: DocumentReference): Promise { const newDocRef = docRef.withConverter(converter); await setDoc(newDocRef, { stringProperty: 'foo', numberProperty: 42 }); await updateDoc(newDocRef, { a: 'newFoo', b: 43 }); @@ -147,7 +147,7 @@ describe('FirestoreTypeConverter', () => { }; } }; - async function foo(docRef: DocumentReference): Promise { + async function _(docRef: DocumentReference): Promise { const newDocRef = docRef.withConverter(converter); await setDoc(newDocRef, { stringProperty: 'foo', numberProperty: 42 }); await updateDoc(newDocRef, { a: 'newFoo', b: 43 }); @@ -178,7 +178,7 @@ describe('FirestoreTypeConverter', () => { }; } }; - async function foo(docRef: DocumentReference): Promise { + async function _(docRef: DocumentReference): Promise { const newDocRef = docRef.withConverter(converter); await setDoc(newDocRef, { stringProperty: 'foo', numberProperty: 42 }); await updateDoc(newDocRef, { a: 'newFoo', b: 43 }); From 0708d3160259908ca47a45ca5ccb31c5072e9ec2 Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Mon, 26 Jun 2023 15:08:35 -0400 Subject: [PATCH 10/10] update class/function docs --- .../firestore_.collectionreference.md | 8 ++-- docs-devsite/firestore_.documentreference.md | 8 ++-- .../firestore_.firestoredataconverter.md | 25 +++++++---- docs-devsite/firestore_.md | 2 +- docs-devsite/firestore_.query.md | 8 ++-- .../firestore_lite.collectionreference.md | 8 ++-- .../firestore_lite.documentreference.md | 8 ++-- .../firestore_lite.firestoredataconverter.md | 25 +++++++---- docs-devsite/firestore_lite.md | 2 +- docs-devsite/firestore_lite.query.md | 8 ++-- packages/firestore/src/api/snapshot.ts | 38 +++++++++++------ packages/firestore/src/lite-api/reference.ts | 25 ++++++----- packages/firestore/src/lite-api/snapshot.ts | 41 +++++++++++++------ 13 files changed, 125 insertions(+), 81 deletions(-) diff --git a/docs-devsite/firestore_.collectionreference.md b/docs-devsite/firestore_.collectionreference.md index 81fd7e218dc..20e54393813 100644 --- a/docs-devsite/firestore_.collectionreference.md +++ b/docs-devsite/firestore_.collectionreference.md @@ -32,7 +32,7 @@ export declare class CollectionReferenceCollectionReference, allowing you to use your own custom model objects with Firestore. When you call [addDoc()](./firestore_.md#adddoc) with the returned CollectionReference instance, the provided converter will convert between Firestore data and your custom type U. | +| [withConverter(converter)](./firestore_.collectionreference.md#collectionreferencewithconverter) | | Applies a custom data converter to this CollectionReference, allowing you to use your own custom model objects with Firestore. When you call [addDoc()](./firestore_.md#adddoc) with the returned CollectionReference instance, the provided converter will convert between Firestore data of type NewDbModelType and your custom type NewAppModelType. | | [withConverter(converter)](./firestore_.collectionreference.md#collectionreferencewithconverter) | | Removes the current converter. | ## CollectionReference.id @@ -77,7 +77,7 @@ readonly type = "collection"; ## CollectionReference.withConverter() -Applies a custom data converter to this `CollectionReference`, allowing you to use your own custom model objects with Firestore. When you call [addDoc()](./firestore_.md#adddoc) with the returned `CollectionReference` instance, the provided converter will convert between Firestore data and your custom type `U`. +Applies a custom data converter to this `CollectionReference`, allowing you to use your own custom model objects with Firestore. When you call [addDoc()](./firestore_.md#adddoc) with the returned `CollectionReference` instance, the provided converter will convert between Firestore data of type `NewDbModelType` and your custom type `NewAppModelType`. Signature: @@ -95,7 +95,7 @@ withConverter(converter: F [CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<NewAppModelType, NewDbModelType> -A `CollectionReference` that uses the provided converter. +A `CollectionReference` that uses the provided converter. ## CollectionReference.withConverter() @@ -117,5 +117,5 @@ withConverter(converter: null): CollectionReference; [CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface), [DocumentData](./firestore_.documentdata.md#documentdata_interface)> -A `CollectionReference` that does not use a converter. +A `CollectionReference` that does not use a converter. diff --git a/docs-devsite/firestore_.documentreference.md b/docs-devsite/firestore_.documentreference.md index cc4d8ecc6b4..c1356ae58f4 100644 --- a/docs-devsite/firestore_.documentreference.md +++ b/docs-devsite/firestore_.documentreference.md @@ -33,7 +33,7 @@ export declare class DocumentReferenceDocumentReference, allowing you to use your own custom model objects with Firestore. When you call [setDoc()](./firestore_lite.md#setdoc), [getDoc()](./firestore_lite.md#getdoc), etc. with the returned DocumentReference instance, the provided converter will convert between Firestore data and your custom type U. | +| [withConverter(converter)](./firestore_.documentreference.md#documentreferencewithconverter) | | Applies a custom data converter to this DocumentReference, allowing you to use your own custom model objects with Firestore. When you call [setDoc()](./firestore_lite.md#setdoc), [getDoc()](./firestore_lite.md#getdoc), etc. with the returned DocumentReference instance, the provided converter will convert between Firestore data of type NewDbModelType and your custom type NewAppModelType. | | [withConverter(converter)](./firestore_.documentreference.md#documentreferencewithconverter) | | Removes the current converter. | ## DocumentReference.converter @@ -98,7 +98,7 @@ readonly type = "document"; ## DocumentReference.withConverter() -Applies a custom data converter to this `DocumentReference`, allowing you to use your own custom model objects with Firestore. When you call [setDoc()](./firestore_lite.md#setdoc), [getDoc()](./firestore_lite.md#getdoc), etc. with the returned `DocumentReference` instance, the provided converter will convert between Firestore data and your custom type `U`. +Applies a custom data converter to this `DocumentReference`, allowing you to use your own custom model objects with Firestore. When you call [setDoc()](./firestore_lite.md#setdoc), [getDoc()](./firestore_lite.md#getdoc), etc. with the returned `DocumentReference` instance, the provided converter will convert between Firestore data of type `NewDbModelType` and your custom type `NewAppModelType`. Signature: @@ -116,7 +116,7 @@ withConverter(converter: F [DocumentReference](./firestore_.documentreference.md#documentreference_class)<NewAppModelType, NewDbModelType> -A `DocumentReference` that uses the provided converter. +A `DocumentReference` that uses the provided converter. ## DocumentReference.withConverter() @@ -138,5 +138,5 @@ withConverter(converter: null): DocumentReference; [DocumentReference](./firestore_.documentreference.md#documentreference_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface), [DocumentData](./firestore_.documentdata.md#documentdata_interface)> -A `DocumentReference` that does not use a converter. +A `DocumentReference` that does not use a converter. diff --git a/docs-devsite/firestore_.firestoredataconverter.md b/docs-devsite/firestore_.firestoredataconverter.md index 246c510e212..700d0f38aaa 100644 --- a/docs-devsite/firestore_.firestoredataconverter.md +++ b/docs-devsite/firestore_.firestoredataconverter.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # FirestoreDataConverter interface -Converter used by `withConverter()` to transform user objects of type `T` into Firestore data. +Converter used by `withConverter()` to transform user objects of type `AppModelType` into Firestore data of type `DbModelType`. Using the converter allows you to specify generic type arguments when storing and retrieving objects from Firestore. @@ -24,13 +24,15 @@ export declare interface FirestoreDataConvertersnapshot.data(options). | -| [toFirestore(modelObject)](./firestore_.firestoredataconverter.md#firestoredataconvertertofirestore) | Called by the Firestore SDK to convert a custom model object of type T into a plain JavaScript object (suitable for writing directly to the Firestore database). To use set() with merge and mergeFields, toFirestore() must be defined with PartialWithFieldValue<T>.The WithFieldValue<T> type extends T to also allow FieldValues such as [deleteField()](./firestore_.md#deletefield) to be used as property values. | -| [toFirestore(modelObject, options)](./firestore_.firestoredataconverter.md#firestoredataconvertertofirestore) | Called by the Firestore SDK to convert a custom model object of type T into a plain JavaScript object (suitable for writing directly to the Firestore database). Used with [setDoc()](./firestore_.md#setdoc), and with merge:true or mergeFields.The PartialWithFieldValue<T> type extends Partial<T> to allow FieldValues such as [arrayUnion()](./firestore_.md#arrayunion) to be used as property values. It also supports nested Partial by allowing nested fields to be omitted. | +| [fromFirestore(snapshot, options)](./firestore_.firestoredataconverter.md#firestoredataconverterfromfirestore) | Called by the Firestore SDK to convert Firestore data into an object of type AppModelType. You can access your data by calling: snapshot.data(options).Generally, the data returned from snapshot.data() can be cast to DbModelType; however, this is not guaranteed as writes to the database may have occurred without a type converter enforcing this specific layout. | +| [toFirestore(modelObject)](./firestore_.firestoredataconverter.md#firestoredataconvertertofirestore) | Called by the Firestore SDK to convert a custom model object of type AppModelType into a plain JavaScript object (suitable for writing directly to the Firestore database) of type DbModelType. To use set() with merge and mergeFields, toFirestore() must be defined with PartialWithFieldValue<AppModelType>.The WithFieldValue<T> type extends T to also allow FieldValues such as [deleteField()](./firestore_.md#deletefield) to be used as property values. | +| [toFirestore(modelObject, options)](./firestore_.firestoredataconverter.md#firestoredataconvertertofirestore) | Called by the Firestore SDK to convert a custom model object of type AppModelType into a plain JavaScript object (suitable for writing directly to the Firestore database) of type DbModelType. Used with [setDoc()](./firestore_.md#setdoc), and with merge:true or mergeFields.The PartialWithFieldValue<T> type extends Partial<T> to allow FieldValues such as [arrayUnion()](./firestore_.md#arrayunion) to be used as property values. It also supports nested Partial by allowing nested fields to be omitted. | ## FirestoreDataConverter.fromFirestore() -Called by the Firestore SDK to convert Firestore data into an object of type T. You can access your data by calling: `snapshot.data(options)`. +Called by the Firestore SDK to convert Firestore data into an object of type `AppModelType`. You can access your data by calling: `snapshot.data(options)`. + +Generally, the data returned from `snapshot.data()` can be cast to `DbModelType`; however, this is not guaranteed as writes to the database may have occurred without a type converter enforcing this specific layout. Signature: @@ -51,7 +53,7 @@ AppModelType ## FirestoreDataConverter.toFirestore() -Called by the Firestore SDK to convert a custom model object of type `T` into a plain JavaScript object (suitable for writing directly to the Firestore database). To use `set()` with `merge` and `mergeFields`, `toFirestore()` must be defined with `PartialWithFieldValue`. +Called by the Firestore SDK to convert a custom model object of type `AppModelType` into a plain JavaScript object (suitable for writing directly to the Firestore database) of type `DbModelType`. To use `set()` with `merge` and `mergeFields`, `toFirestore()` must be defined with `PartialWithFieldValue`. The `WithFieldValue` type extends `T` to also allow FieldValues such as [deleteField()](./firestore_.md#deletefield) to be used as property values. @@ -73,7 +75,7 @@ toFirestore(modelObject: WithFieldValue): WithFieldValue, and with `merge:true` or `mergeFields`. +Called by the Firestore SDK to convert a custom model object of type `AppModelType` into a plain JavaScript object (suitable for writing directly to the Firestore database) of type `DbModelType`. Used with [setDoc()](./firestore_.md#setdoc), and with `merge:true` or `mergeFields`. The `PartialWithFieldValue` type extends `Partial` to allow FieldValues such as [arrayUnion()](./firestore_.md#arrayunion) to be used as property values. It also supports nested `Partial` by allowing nested fields to be omitted. @@ -106,15 +108,20 @@ class Post { } } +interface PostDbModel { + title: string; + author: string; +} + const postConverter = { - toFirestore(post: WithFieldValue): DocumentData { + toFirestore(post: WithFieldValue): PostDbModel { return {title: post.title, author: post.author}; }, fromFirestore( snapshot: QueryDocumentSnapshot, options: SnapshotOptions ): Post { - const data = snapshot.data(options)!; + const data = snapshot.data(options) as PostDbModel; return new Post(data.title, data.author); } }; diff --git a/docs-devsite/firestore_.md b/docs-devsite/firestore_.md index 8491c3e7d4b..462635b0f85 100644 --- a/docs-devsite/firestore_.md +++ b/docs-devsite/firestore_.md @@ -153,7 +153,7 @@ https://github.com/firebase/firebase-js-sdk | [DocumentChange](./firestore_.documentchange.md#documentchange_interface) | A DocumentChange represents a change to the documents matching a query. It contains the document affected and the type of change that occurred. | | [DocumentData](./firestore_.documentdata.md#documentdata_interface) | Document data (for use with [setDoc()](./firestore_lite.md#setdoc)) consists of fields mapped to values. | | [ExperimentalLongPollingOptions](./firestore_.experimentallongpollingoptions.md#experimentallongpollingoptions_interface) | Options that configure the SDK’s underlying network transport (WebChannel) when long-polling is used.Note: This interface is "experimental" and is subject to change.See FirestoreSettings.experimentalAutoDetectLongPolling, FirestoreSettings.experimentalForceLongPolling, and FirestoreSettings.experimentalLongPollingOptions. | -| [FirestoreDataConverter](./firestore_.firestoredataconverter.md#firestoredataconverter_interface) | Converter used by withConverter() to transform user objects of type T into Firestore data.Using the converter allows you to specify generic type arguments when storing and retrieving objects from Firestore. | +| [FirestoreDataConverter](./firestore_.firestoredataconverter.md#firestoredataconverter_interface) | Converter used by withConverter() to transform user objects of type AppModelType into Firestore data of type DbModelType.Using the converter allows you to specify generic type arguments when storing and retrieving objects from Firestore. | | [FirestoreSettings](./firestore_.firestoresettings.md#firestoresettings_interface) | Specifies custom configurations for your Cloud Firestore instance. You must set these before invoking any other methods. | | [Index](./firestore_.index.md#index_interface) | (BETA) The SDK definition of a Firestore index. | | [IndexConfiguration](./firestore_.indexconfiguration.md#indexconfiguration_interface) | (BETA) A list of Firestore indexes to speed up local query execution.See [JSON Format](https://firebase.google.com/docs/reference/firestore/indexes/#json_format) for a description of the format of the index definition. | diff --git a/docs-devsite/firestore_.query.md b/docs-devsite/firestore_.query.md index 7e7cea4fb45..678ab1faf89 100644 --- a/docs-devsite/firestore_.query.md +++ b/docs-devsite/firestore_.query.md @@ -37,7 +37,7 @@ export declare class QueryU. | +| [withConverter(converter)](./firestore_.query.md#querywithconverter) | | Applies a custom data converter to this query, allowing you to use your own custom model objects with Firestore. When you call [getDocs()](./firestore_.md#getdocs) with the returned query, the provided converter will convert between Firestore data of type NewDbModelType and your custom type NewAppModelType. | ## Query.(constructor) @@ -99,11 +99,11 @@ withConverter(converter: null): Query; [Query](./firestore_.query.md#query_class)<[DocumentData](./firestore_.documentdata.md#documentdata_interface), [DocumentData](./firestore_.documentdata.md#documentdata_interface)> -A `Query` that does not use a converter. +A `Query` that does not use a converter. ## Query.withConverter() -Applies a custom data converter to this query, allowing you to use your own custom model objects with Firestore. When you call [getDocs()](./firestore_.md#getdocs) with the returned query, the provided converter will convert between Firestore data and your custom type `U`. +Applies a custom data converter to this query, allowing you to use your own custom model objects with Firestore. When you call [getDocs()](./firestore_.md#getdocs) with the returned query, the provided converter will convert between Firestore data of type `NewDbModelType` and your custom type `NewAppModelType`. Signature: @@ -121,5 +121,5 @@ withConverter(converter: F [Query](./firestore_.query.md#query_class)<NewAppModelType, NewDbModelType> -A `Query` that uses the provided converter. +A `Query` that uses the provided converter. diff --git a/docs-devsite/firestore_lite.collectionreference.md b/docs-devsite/firestore_lite.collectionreference.md index 18e64e719eb..0cb088d24f1 100644 --- a/docs-devsite/firestore_lite.collectionreference.md +++ b/docs-devsite/firestore_lite.collectionreference.md @@ -32,7 +32,7 @@ export declare class CollectionReferenceCollectionReference, allowing you to use your own custom model objects with Firestore. When you call [addDoc()](./firestore_.md#adddoc) with the returned CollectionReference instance, the provided converter will convert between Firestore data and your custom type U. | +| [withConverter(converter)](./firestore_lite.collectionreference.md#collectionreferencewithconverter) | | Applies a custom data converter to this CollectionReference, allowing you to use your own custom model objects with Firestore. When you call [addDoc()](./firestore_.md#adddoc) with the returned CollectionReference instance, the provided converter will convert between Firestore data of type NewDbModelType and your custom type NewAppModelType. | | [withConverter(converter)](./firestore_lite.collectionreference.md#collectionreferencewithconverter) | | Removes the current converter. | ## CollectionReference.id @@ -77,7 +77,7 @@ readonly type = "collection"; ## CollectionReference.withConverter() -Applies a custom data converter to this `CollectionReference`, allowing you to use your own custom model objects with Firestore. When you call [addDoc()](./firestore_.md#adddoc) with the returned `CollectionReference` instance, the provided converter will convert between Firestore data and your custom type `U`. +Applies a custom data converter to this `CollectionReference`, allowing you to use your own custom model objects with Firestore. When you call [addDoc()](./firestore_.md#adddoc) with the returned `CollectionReference` instance, the provided converter will convert between Firestore data of type `NewDbModelType` and your custom type `NewAppModelType`. Signature: @@ -95,7 +95,7 @@ withConverter(converter: F [CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<NewAppModelType, NewDbModelType> -A `CollectionReference` that uses the provided converter. +A `CollectionReference` that uses the provided converter. ## CollectionReference.withConverter() @@ -117,5 +117,5 @@ withConverter(converter: null): CollectionReference; [CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface), [DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> -A `CollectionReference` that does not use a converter. +A `CollectionReference` that does not use a converter. diff --git a/docs-devsite/firestore_lite.documentreference.md b/docs-devsite/firestore_lite.documentreference.md index 7c02494faf4..dc053598c1b 100644 --- a/docs-devsite/firestore_lite.documentreference.md +++ b/docs-devsite/firestore_lite.documentreference.md @@ -33,7 +33,7 @@ export declare class DocumentReferenceDocumentReference, allowing you to use your own custom model objects with Firestore. When you call [setDoc()](./firestore_lite.md#setdoc), [getDoc()](./firestore_lite.md#getdoc), etc. with the returned DocumentReference instance, the provided converter will convert between Firestore data and your custom type U. | +| [withConverter(converter)](./firestore_lite.documentreference.md#documentreferencewithconverter) | | Applies a custom data converter to this DocumentReference, allowing you to use your own custom model objects with Firestore. When you call [setDoc()](./firestore_lite.md#setdoc), [getDoc()](./firestore_lite.md#getdoc), etc. with the returned DocumentReference instance, the provided converter will convert between Firestore data of type NewDbModelType and your custom type NewAppModelType. | | [withConverter(converter)](./firestore_lite.documentreference.md#documentreferencewithconverter) | | Removes the current converter. | ## DocumentReference.converter @@ -98,7 +98,7 @@ readonly type = "document"; ## DocumentReference.withConverter() -Applies a custom data converter to this `DocumentReference`, allowing you to use your own custom model objects with Firestore. When you call [setDoc()](./firestore_lite.md#setdoc), [getDoc()](./firestore_lite.md#getdoc), etc. with the returned `DocumentReference` instance, the provided converter will convert between Firestore data and your custom type `U`. +Applies a custom data converter to this `DocumentReference`, allowing you to use your own custom model objects with Firestore. When you call [setDoc()](./firestore_lite.md#setdoc), [getDoc()](./firestore_lite.md#getdoc), etc. with the returned `DocumentReference` instance, the provided converter will convert between Firestore data of type `NewDbModelType` and your custom type `NewAppModelType`. Signature: @@ -116,7 +116,7 @@ withConverter(converter: F [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<NewAppModelType, NewDbModelType> -A `DocumentReference` that uses the provided converter. +A `DocumentReference` that uses the provided converter. ## DocumentReference.withConverter() @@ -138,5 +138,5 @@ withConverter(converter: null): DocumentReference; [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface), [DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> -A `DocumentReference` that does not use a converter. +A `DocumentReference` that does not use a converter. diff --git a/docs-devsite/firestore_lite.firestoredataconverter.md b/docs-devsite/firestore_lite.firestoredataconverter.md index e508471ecfa..660f04f371f 100644 --- a/docs-devsite/firestore_lite.firestoredataconverter.md +++ b/docs-devsite/firestore_lite.firestoredataconverter.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # FirestoreDataConverter interface -Converter used by `withConverter()` to transform user objects of type `T` into Firestore data. +Converter used by `withConverter()` to transform user objects of type `AppModelType` into Firestore data of type `DbModelType`. Using the converter allows you to specify generic type arguments when storing and retrieving objects from Firestore. @@ -24,13 +24,15 @@ export declare interface FirestoreDataConvertersnapshot.data(). | -| [toFirestore(modelObject)](./firestore_lite.firestoredataconverter.md#firestoredataconvertertofirestore) | Called by the Firestore SDK to convert a custom model object of type T into a plain Javascript object (suitable for writing directly to the Firestore database). Used with [setDoc()](./firestore_lite.md#setdoc), and .The WithFieldValue<T> type extends T to also allow FieldValues such as [deleteField()](./firestore_.md#deletefield) to be used as property values. | -| [toFirestore(modelObject, options)](./firestore_lite.firestoredataconverter.md#firestoredataconvertertofirestore) | Called by the Firestore SDK to convert a custom model object of type T into a plain Javascript object (suitable for writing directly to the Firestore database). Used with [setDoc()](./firestore_lite.md#setdoc), and with merge:true or mergeFields.The PartialWithFieldValue<T> type extends Partial<T> to allow FieldValues such as [arrayUnion()](./firestore_.md#arrayunion) to be used as property values. It also supports nested Partial by allowing nested fields to be omitted. | +| [fromFirestore(snapshot)](./firestore_lite.firestoredataconverter.md#firestoredataconverterfromfirestore) | Called by the Firestore SDK to convert Firestore data into an object of type AppModelType. You can access your data by calling: snapshot.data().Generally, the data returned from snapshot.data() can be cast to DbModelType; however, this is not guaranteed as writes to the database may have occurred without a type converter enforcing this specific layout. | +| [toFirestore(modelObject)](./firestore_lite.firestoredataconverter.md#firestoredataconvertertofirestore) | Called by the Firestore SDK to convert a custom model object of type AppModelType into a plain Javascript object (suitable for writing directly to the Firestore database) of type DbModelType. Used with [setDoc()](./firestore_lite.md#setdoc), and .The WithFieldValue<T> type extends T to also allow FieldValues such as [deleteField()](./firestore_.md#deletefield) to be used as property values. | +| [toFirestore(modelObject, options)](./firestore_lite.firestoredataconverter.md#firestoredataconvertertofirestore) | Called by the Firestore SDK to convert a custom model object of type AppModelType into a plain Javascript object (suitable for writing directly to the Firestore database) of type DbModelType. Used with [setDoc()](./firestore_lite.md#setdoc), and with merge:true or mergeFields.The PartialWithFieldValue<T> type extends Partial<T> to allow FieldValues such as [arrayUnion()](./firestore_.md#arrayunion) to be used as property values. It also supports nested Partial by allowing nested fields to be omitted. | ## FirestoreDataConverter.fromFirestore() -Called by the Firestore SDK to convert Firestore data into an object of type T. You can access your data by calling: `snapshot.data()`. +Called by the Firestore SDK to convert Firestore data into an object of type `AppModelType`. You can access your data by calling: `snapshot.data()`. + +Generally, the data returned from `snapshot.data()` can be cast to `DbModelType`; however, this is not guaranteed as writes to the database may have occurred without a type converter enforcing this specific layout. Signature: @@ -50,7 +52,7 @@ AppModelType ## FirestoreDataConverter.toFirestore() -Called by the Firestore SDK to convert a custom model object of type `T` into a plain Javascript object (suitable for writing directly to the Firestore database). Used with [setDoc()](./firestore_lite.md#setdoc), and . +Called by the Firestore SDK to convert a custom model object of type `AppModelType` into a plain Javascript object (suitable for writing directly to the Firestore database) of type `DbModelType`. Used with [setDoc()](./firestore_lite.md#setdoc), and . The `WithFieldValue` type extends `T` to also allow FieldValues such as [deleteField()](./firestore_.md#deletefield) to be used as property values. @@ -72,7 +74,7 @@ toFirestore(modelObject: WithFieldValue): WithFieldValue, and with `merge:true` or `mergeFields`. +Called by the Firestore SDK to convert a custom model object of type `AppModelType` into a plain Javascript object (suitable for writing directly to the Firestore database) of type `DbModelType`. Used with [setDoc()](./firestore_lite.md#setdoc), and with `merge:true` or `mergeFields`. The `PartialWithFieldValue` type extends `Partial` to allow FieldValues such as [arrayUnion()](./firestore_.md#arrayunion) to be used as property values. It also supports nested `Partial` by allowing nested fields to be omitted. @@ -105,12 +107,17 @@ class Post { } } +interface PostDbModel { + title: string; + author: string; +} + const postConverter = { - toFirestore(post: WithFieldValue): DocumentData { + toFirestore(post: WithFieldValue): PostDbModel { return {title: post.title, author: post.author}; }, fromFirestore(snapshot: QueryDocumentSnapshot): Post { - const data = snapshot.data(options)!; + const data = snapshot.data(options) as PostDbModel; return new Post(data.title, data.author); } }; diff --git a/docs-devsite/firestore_lite.md b/docs-devsite/firestore_lite.md index d53476ba417..b87e2417b93 100644 --- a/docs-devsite/firestore_lite.md +++ b/docs-devsite/firestore_lite.md @@ -119,7 +119,7 @@ https://github.com/firebase/firebase-js-sdk | --- | --- | | [AggregateSpec](./firestore_lite.aggregatespec.md#aggregatespec_interface) | Specifies a set of aggregations and their aliases. | | [DocumentData](./firestore_lite.documentdata.md#documentdata_interface) | Document data (for use with [setDoc()](./firestore_lite.md#setdoc)) consists of fields mapped to values. | -| [FirestoreDataConverter](./firestore_lite.firestoredataconverter.md#firestoredataconverter_interface) | Converter used by withConverter() to transform user objects of type T into Firestore data.Using the converter allows you to specify generic type arguments when storing and retrieving objects from Firestore. | +| [FirestoreDataConverter](./firestore_lite.firestoredataconverter.md#firestoredataconverter_interface) | Converter used by withConverter() to transform user objects of type AppModelType into Firestore data of type DbModelType.Using the converter allows you to specify generic type arguments when storing and retrieving objects from Firestore. | | [Settings](./firestore_lite.settings.md#settings_interface) | Specifies custom configurations for your Cloud Firestore instance. You must set these before invoking any other methods. | | [TransactionOptions](./firestore_lite.transactionoptions.md#transactionoptions_interface) | Options to customize transaction behavior. | diff --git a/docs-devsite/firestore_lite.query.md b/docs-devsite/firestore_lite.query.md index d3b72d1ed04..093a8532bb4 100644 --- a/docs-devsite/firestore_lite.query.md +++ b/docs-devsite/firestore_lite.query.md @@ -37,7 +37,7 @@ export declare class QueryU. | +| [withConverter(converter)](./firestore_lite.query.md#querywithconverter) | | Applies a custom data converter to this query, allowing you to use your own custom model objects with Firestore. When you call [getDocs()](./firestore_.md#getdocs) with the returned query, the provided converter will convert between Firestore data of type NewDbModelType and your custom type NewAppModelType. | ## Query.(constructor) @@ -99,11 +99,11 @@ withConverter(converter: null): Query; [Query](./firestore_lite.query.md#query_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface), [DocumentData](./firestore_lite.documentdata.md#documentdata_interface)> -A `Query` that does not use a converter. +A `Query` that does not use a converter. ## Query.withConverter() -Applies a custom data converter to this query, allowing you to use your own custom model objects with Firestore. When you call [getDocs()](./firestore_.md#getdocs) with the returned query, the provided converter will convert between Firestore data and your custom type `U`. +Applies a custom data converter to this query, allowing you to use your own custom model objects with Firestore. When you call [getDocs()](./firestore_.md#getdocs) with the returned query, the provided converter will convert between Firestore data of type `NewDbModelType` and your custom type `NewAppModelType`. Signature: @@ -121,5 +121,5 @@ withConverter(converter: F [Query](./firestore_lite.query.md#query_class)<NewAppModelType, NewDbModelType> -A `Query` that uses the provided converter. +A `Query` that uses the provided converter. diff --git a/packages/firestore/src/api/snapshot.ts b/packages/firestore/src/api/snapshot.ts index 85671408f1d..9c266d91867 100644 --- a/packages/firestore/src/api/snapshot.ts +++ b/packages/firestore/src/api/snapshot.ts @@ -42,8 +42,8 @@ import { Firestore } from './database'; import { SnapshotListenOptions } from './reference_impl'; /** - * Converter used by `withConverter()` to transform user objects of type `T` - * into Firestore data. + * Converter used by `withConverter()` to transform user objects of type + * `AppModelType` into Firestore data of type `DbModelType`. * * Using the converter allows you to specify generic type arguments when * storing and retrieving objects from Firestore. @@ -58,15 +58,20 @@ import { SnapshotListenOptions } from './reference_impl'; * } * } * + * interface PostDbModel { + * title: string; + * author: string; + * } + * * const postConverter = { - * toFirestore(post: WithFieldValue): DocumentData { + * toFirestore(post: WithFieldValue): PostDbModel { * return {title: post.title, author: post.author}; * }, * fromFirestore( * snapshot: QueryDocumentSnapshot, * options: SnapshotOptions * ): Post { - * const data = snapshot.data(options)!; + * const data = snapshot.data(options) as PostDbModel; * return new Post(data.title, data.author); * } * }; @@ -88,10 +93,11 @@ export interface FirestoreDataConverter< DbModelType extends DocumentData = DocumentData > extends LiteFirestoreDataConverter { /** - * Called by the Firestore SDK to convert a custom model object of type `T` - * into a plain JavaScript object (suitable for writing directly to the - * Firestore database). To use `set()` with `merge` and `mergeFields`, - * `toFirestore()` must be defined with `PartialWithFieldValue`. + * Called by the Firestore SDK to convert a custom model object of type + * `AppModelType` into a plain JavaScript object (suitable for writing + * directly to the Firestore database) of type `DbModelType`. To use `set()` + * with `merge` and `mergeFields`, `toFirestore()` must be defined with + * `PartialWithFieldValue`. * * The `WithFieldValue` type extends `T` to also allow FieldValues such as * {@link (deleteField:1)} to be used as property values. @@ -101,10 +107,11 @@ export interface FirestoreDataConverter< ): WithFieldValue; /** - * Called by the Firestore SDK to convert a custom model object of type `T` - * into a plain JavaScript object (suitable for writing directly to the - * Firestore database). Used with {@link (setDoc:1)}, {@link (WriteBatch.set:1)} - * and {@link (Transaction.set:1)} with `merge:true` or `mergeFields`. + * Called by the Firestore SDK to convert a custom model object of type + * `AppModelType` into a plain JavaScript object (suitable for writing + * directly to the Firestore database) of type `DbModelType`. Used with + * {@link (setDoc:1)}, {@link (WriteBatch.set:1)} and + * {@link (Transaction.set:1)} with `merge:true` or `mergeFields`. * * The `PartialWithFieldValue` type extends `Partial` to allow * FieldValues such as {@link (arrayUnion:1)} to be used as property values. @@ -118,7 +125,12 @@ export interface FirestoreDataConverter< /** * Called by the Firestore SDK to convert Firestore data into an object of - * type T. You can access your data by calling: `snapshot.data(options)`. + * type `AppModelType`. You can access your data by calling: + * `snapshot.data(options)`. + * + * Generally, the data returned from `snapshot.data()` can be cast to + * `DbModelType`; however, this is not guaranteed as writes to the database + * may have occurred without a type converter enforcing this specific layout. * * @param snapshot - A `QueryDocumentSnapshot` containing your data and metadata. * @param options - The `SnapshotOptions` from the initial call to `data()`. diff --git a/packages/firestore/src/lite-api/reference.ts b/packages/firestore/src/lite-api/reference.ts index 466e22caf39..6272f3594a9 100644 --- a/packages/firestore/src/lite-api/reference.ts +++ b/packages/firestore/src/lite-api/reference.ts @@ -146,17 +146,18 @@ export class Query< * Removes the current converter. * * @param converter - `null` removes the current converter. - * @returns A `Query` that does not use a converter. + * @returns A `Query` that does not use a + * converter. */ withConverter(converter: null): Query; /** * Applies a custom data converter to this query, allowing you to use your own * custom model objects with Firestore. When you call {@link getDocs} with * the returned query, the provided converter will convert between Firestore - * data and your custom type `U`. + * data of type `NewDbModelType` and your custom type `NewAppModelType`. * * @param converter - Converts objects to and from Firestore. - * @returns A `Query` that uses the provided converter. + * @returns A `Query` that uses the provided converter. */ withConverter( converter: FirestoreDataConverter @@ -239,11 +240,11 @@ export class DocumentReference< * Applies a custom data converter to this `DocumentReference`, allowing you * to use your own custom model objects with Firestore. When you call {@link * @firebase/firestore/lite#(setDoc:1)}, {@link @firebase/firestore/lite#getDoc}, etc. with the returned `DocumentReference` - * instance, the provided converter will convert between Firestore data and - * your custom type `U`. + * instance, the provided converter will convert between Firestore data of + * type `NewDbModelType` and your custom type `NewAppModelType`. * * @param converter - Converts objects to and from Firestore. - * @returns A `DocumentReference` that uses the provided converter. + * @returns A `DocumentReference` that uses the provided converter. */ withConverter( converter: FirestoreDataConverter @@ -252,7 +253,8 @@ export class DocumentReference< * Removes the current converter. * * @param converter - `null` removes the current converter. - * @returns A `DocumentReference` that does not use a converter. + * @returns A `DocumentReference` that does not + * use a converter. */ withConverter(converter: null): DocumentReference; withConverter( @@ -320,10 +322,11 @@ export class CollectionReference< * Applies a custom data converter to this `CollectionReference`, allowing you * to use your own custom model objects with Firestore. When you call {@link * addDoc} with the returned `CollectionReference` instance, the provided - * converter will convert between Firestore data and your custom type `U`. + * converter will convert between Firestore data of type `NewDbModelType` and + * your custom type `NewAppModelType`. * * @param converter - Converts objects to and from Firestore. - * @returns A `CollectionReference` that uses the provided converter. + * @returns A `CollectionReference` that uses the provided converter. */ withConverter( converter: FirestoreDataConverter @@ -332,8 +335,8 @@ export class CollectionReference< * Removes the current converter. * * @param converter - `null` removes the current converter. - * @returns A `CollectionReference` that does not use a - * converter. + * @returns A `CollectionReference` that does not + * use a converter. */ withConverter( converter: null diff --git a/packages/firestore/src/lite-api/snapshot.ts b/packages/firestore/src/lite-api/snapshot.ts index 9c268eeb52c..5d243cabc25 100644 --- a/packages/firestore/src/lite-api/snapshot.ts +++ b/packages/firestore/src/lite-api/snapshot.ts @@ -40,8 +40,8 @@ import { import { AbstractUserDataWriter } from './user_data_writer'; /** - * Converter used by `withConverter()` to transform user objects of type `T` - * into Firestore data. + * Converter used by `withConverter()` to transform user objects of type + * `AppModelType` into Firestore data of type `DbModelType`. * * Using the converter allows you to specify generic type arguments when * storing and retrieving objects from Firestore. @@ -56,12 +56,17 @@ import { AbstractUserDataWriter } from './user_data_writer'; * } * } * + * interface PostDbModel { + * title: string; + * author: string; + * } + * * const postConverter = { - * toFirestore(post: WithFieldValue): DocumentData { + * toFirestore(post: WithFieldValue): PostDbModel { * return {title: post.title, author: post.author}; * }, * fromFirestore(snapshot: QueryDocumentSnapshot): Post { - * const data = snapshot.data(options)!; + * const data = snapshot.data(options) as PostDbModel; * return new Post(data.title, data.author); * } * }; @@ -83,10 +88,12 @@ export interface FirestoreDataConverter< DbModelType extends DocumentData = DocumentData > { /** - * Called by the Firestore SDK to convert a custom model object of type `T` - * into a plain Javascript object (suitable for writing directly to the - * Firestore database). Used with {@link @firebase/firestore/lite#(setDoc:1)}, {@link @firebase/firestore/lite#(WriteBatch.set:1)} - * and {@link @firebase/firestore/lite#(Transaction.set:1)}. + * Called by the Firestore SDK to convert a custom model object of type + * `AppModelType` into a plain Javascript object (suitable for writing + * directly to the Firestore database) of type `DbModelType`. Used with + * {@link @firebase/firestore/lite#(setDoc:1)}, + * {@link @firebase/firestore/lite#(WriteBatch.set:1)} and + * {@link @firebase/firestore/lite#(Transaction.set:1)}. * * The `WithFieldValue` type extends `T` to also allow FieldValues such as * {@link (deleteField:1)} to be used as property values. @@ -96,10 +103,13 @@ export interface FirestoreDataConverter< ): WithFieldValue; /** - * Called by the Firestore SDK to convert a custom model object of type `T` - * into a plain Javascript object (suitable for writing directly to the - * Firestore database). Used with {@link @firebase/firestore/lite#(setDoc:1)}, {@link @firebase/firestore/lite#(WriteBatch.set:1)} - * and {@link @firebase/firestore/lite#(Transaction.set:1)} with `merge:true` or `mergeFields`. + * Called by the Firestore SDK to convert a custom model object of type + * `AppModelType` into a plain Javascript object (suitable for writing + * directly to the Firestore database) of type `DbModelType`. Used with + * {@link @firebase/firestore/lite#(setDoc:1)}, + * {@link @firebase/firestore/lite#(WriteBatch.set:1)} and + * {@link @firebase/firestore/lite#(Transaction.set:1)} with `merge:true` + * or `mergeFields`. * * The `PartialWithFieldValue` type extends `Partial` to allow * FieldValues such as {@link (arrayUnion:1)} to be used as property values. @@ -113,7 +123,12 @@ export interface FirestoreDataConverter< /** * Called by the Firestore SDK to convert Firestore data into an object of - * type T. You can access your data by calling: `snapshot.data()`. + * type `AppModelType`. You can access your data by calling: + * `snapshot.data()`. + * + * Generally, the data returned from `snapshot.data()` can be cast to + * `DbModelType`; however, this is not guaranteed as writes to the database + * may have occurred without a type converter enforcing this specific layout. * * @param snapshot - A `QueryDocumentSnapshot` containing your data and * metadata.