From a152ffac94ce09baa2be3496f2cf62f2d7c33e02 Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Thu, 6 Apr 2023 20:27:36 -0400 Subject: [PATCH 1/9] work --- packages/firestore/src/lite-api/reference.ts | 117 +++++++++--------- packages/firestore/src/lite-api/snapshot.ts | 36 +++--- .../firestore/src/lite-api/transaction.ts | 3 +- .../src/lite-api/user_data_reader.ts | 10 +- 4 files changed, 80 insertions(+), 86 deletions(-) diff --git a/packages/firestore/src/lite-api/reference.ts b/packages/firestore/src/lite-api/reference.ts index 0a9fdcf71cd..fd47405efd2 100644 --- a/packages/firestore/src/lite-api/reference.ts +++ b/packages/firestore/src/lite-api/reference.ts @@ -41,14 +41,11 @@ import { FirestoreDataConverter } from './snapshot'; import { NestedUpdateFields, Primitive } from './types'; /** - * Document data (for use with {@link @firebase/firestore/lite#(setDoc:1)}) consists of fields mapped to - * values. + * Document data (for use with {@link @firebase/firestore/lite#(setDoc:1)}). + * Must be an object with string keys. */ -export interface DocumentData { - /** A mapping between a field and its value. */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - [field: string]: any; -} +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export type DocumentData = Record; /** * Similar to Typescript's `Partial`, but allows nested fields to be @@ -113,7 +110,7 @@ export type SetOptions = * 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 { /** The type of this Firestore reference. */ readonly type = 'document'; @@ -129,7 +126,7 @@ export class DocumentReference { /** * If provided, the `FirestoreDataConverter` associated with this instance. */ - readonly converter: FirestoreDataConverter | null, + readonly converter: FirestoreDataConverter | null, readonly _key: DocumentKey ) { this.firestore = firestore; @@ -157,8 +154,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,7 +172,7 @@ 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. * @@ -183,10 +180,10 @@ export class DocumentReference { * @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); + withConverter( + converter: FirestoreDataConverter | null + ): DocumentReference { + return new DocumentReference(this.firestore, converter, this._key); } } @@ -194,7 +191,7 @@ export class DocumentReference { * 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 { +export class Query { /** The type of this Firestore reference. */ readonly type: 'query' | 'collection' = 'query'; @@ -212,7 +209,7 @@ export class Query { /** * If provided, the `FirestoreDataConverter` associated with this instance. */ - readonly converter: FirestoreDataConverter | null, + readonly converter: FirestoreDataConverter | null, readonly _query: InternalQuery ) { this.firestore = firestore; @@ -224,7 +221,7 @@ export class Query { * @param converter - `null` removes the current converter. * @returns A `Query` that does not use a converter. */ - withConverter(converter: null): Query; + 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 @@ -234,9 +231,9 @@ export class Query { * @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: FirestoreDataConverter): Query; + withConverter(converter: FirestoreDataConverter | null): Query { + return new Query(this.firestore, converter, this._query); } } @@ -244,14 +241,14 @@ 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 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,12 +271,12 @@ 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; } else { - return new DocumentReference( + return new DocumentReference( this.firestore, /* converter= */ null, new DocumentKey(parentPath) @@ -296,9 +293,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 +303,9 @@ 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 +325,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 +338,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 +355,16 @@ 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); @@ -392,7 +387,7 @@ export function collection( ResourcePath.fromString(path, ...pathSegments) ); validateCollectionPath(absolutePath); - return new CollectionReference( + return new CollectionReference( parent.firestore, /* converter= */ null, absolutePath @@ -417,7 +412,7 @@ export function collection( export function collectionGroup( firestore: Firestore, collectionId: string -): Query { +): Query { firestore = cast(firestore, Firestore); validateNonEmptyArgument('collectionGroup', 'collection id', collectionId); @@ -429,7 +424,7 @@ export function collectionGroup( ); } - return new Query( + return new Query( firestore, /* converter= */ null, newQueryForCollectionGroup(collectionId) @@ -452,7 +447,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 +463,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 +480,16 @@ 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 @@ -543,9 +538,9 @@ 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 +568,7 @@ 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/snapshot.ts b/packages/firestore/src/lite-api/snapshot.ts index d726d92a7e4..d00086740bd 100644 --- a/packages/firestore/src/lite-api/snapshot.ts +++ b/packages/firestore/src/lite-api/snapshot.ts @@ -78,7 +78,7 @@ import { AbstractUserDataWriter } from './user_data_writer'; * } * ``` */ -export interface FirestoreDataConverter { +export interface FirestoreDataConverter { /** * 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 +88,7 @@ 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 +102,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 +113,7 @@ export interface FirestoreDataConverter { * @param snapshot - A `QueryDocumentSnapshot` containing your data and * metadata. */ - fromFirestore(snapshot: QueryDocumentSnapshot): T; + fromFirestore(snapshot: QueryDocumentSnapshot): AppType; } /** @@ -125,7 +125,7 @@ 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 { // Note: This class is stripped down version of the DocumentSnapshot in // the legacy SDK. The changes are: // - No support for SnapshotMetadata. @@ -137,7 +137,7 @@ export class DocumentSnapshot { public _userDataWriter: AbstractUserDataWriter, public _key: DocumentKey, public _document: Document | null, - public _converter: UntypedFirestoreDataConverter | null + public _converter: UntypedFirestoreDataConverter | null ) {} /** Property of the `DocumentSnapshot` that provides the document's ID. */ @@ -148,8 +148,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 +161,7 @@ export class DocumentSnapshot { * * @returns true if the document exists. */ - exists(): this is QueryDocumentSnapshot { + exists(): this is QueryDocumentSnapshot { return this._document !== null; } @@ -172,7 +172,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(): AppType | undefined { if (!this._document) { return undefined; } else if (this._converter) { @@ -187,7 +187,7 @@ 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 AppType; } } @@ -226,17 +226,15 @@ export class DocumentSnapshot { * `exists` property will always be true and `data()` will never return * 'undefined'. */ -export class QueryDocumentSnapshot< - T = DocumentData -> extends DocumentSnapshot { +export class QueryDocumentSnapshot 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(): AppType { + return super.data() as AppType; } } @@ -247,12 +245,12 @@ export class QueryDocumentSnapshot< * number of documents can be determined via the `empty` and `size` * properties. */ -export class QuerySnapshot { +export class QuerySnapshot { /** * The query on which you called {@link getDocs} in order to get this * `QuerySnapshot`. */ - readonly query: Query; + readonly query: Query; /** @hideconstructor */ constructor( diff --git a/packages/firestore/src/lite-api/transaction.ts b/packages/firestore/src/lite-api/transaction.ts index aab718cf91d..a1724ee0960 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,7 @@ 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 => { diff --git a/packages/firestore/src/lite-api/user_data_reader.ts b/packages/firestore/src/lite-api/user_data_reader.ts index 0f869ca87e6..d384c6e3a79 100644 --- a/packages/firestore/src/lite-api/user_data_reader.ts +++ b/packages/firestore/src/lite-api/user_data_reader.ts @@ -76,13 +76,13 @@ 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 { + toFirestore(modelObject: WithFieldValue): WithFieldValue; toFirestore( - modelObject: PartialWithFieldValue, + modelObject: PartialWithFieldValue, options: SetOptions - ): DocumentData; - fromFirestore(snapshot: unknown, options?: unknown): T; + ): PartialWithFieldValue; + fromFirestore(snapshot: unknown, options?: unknown): AppType; } /** The result of parsing document data (e.g. for a setData call). */ From a93a35397be0ebae30531bafd421b66af3a1da67 Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Mon, 17 Apr 2023 15:06:24 -0400 Subject: [PATCH 2/9] done lite sdk --- packages/firestore/src/lite-api/aggregate.ts | 28 +++---- .../firestore/src/lite-api/aggregate_types.ts | 12 +-- packages/firestore/src/lite-api/query.ts | 54 ++++++------ packages/firestore/src/lite-api/reference.ts | 6 +- .../firestore/src/lite-api/reference_impl.ts | 82 +++++++++---------- packages/firestore/src/lite-api/snapshot.ts | 28 ++++--- 6 files changed, 106 insertions(+), 104 deletions(-) diff --git a/packages/firestore/src/lite-api/aggregate.ts b/packages/firestore/src/lite-api/aggregate.ts index 0895d8f89c5..fc6de2d045c 100644 --- a/packages/firestore/src/lite-api/aggregate.ts +++ b/packages/firestore/src/lite-api/aggregate.ts @@ -32,7 +32,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'; @@ -50,9 +50,9 @@ 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 }, AppType, DbType>> { const countQuerySpec: { count: AggregateField } = { count: count() }; @@ -87,10 +87,10 @@ export function getCount( * ``` * @internal TODO (sum/avg) remove when public */ -export function getAggregate( - query: Query, - aggregateSpec: T -): Promise> { +export function getAggregate( + query: Query, + aggregateSpec: AggregateSpecType +): Promise> { const firestore = cast(query.firestore, Firestore); const datastore = getDatastore(firestore); @@ -112,17 +112,13 @@ export function getAggregate( ); } -function convertToAggregateQuerySnapshot( +function convertToAggregateQuerySnapshot( firestore: Firestore, - query: Query, + query: Query, aggregateResult: ObjectValue -): AggregateQuerySnapshot { +): AggregateQuerySnapshot { const userDataWriter = new LiteUserDataWriter(firestore); - const querySnapshot = new AggregateQuerySnapshot( - query, - userDataWriter, - aggregateResult - ); + const querySnapshot = new AggregateQuerySnapshot(query, userDataWriter, aggregateResult); return querySnapshot; } diff --git a/packages/firestore/src/lite-api/aggregate_types.ts b/packages/firestore/src/lite-api/aggregate_types.ts index ab9619b58b4..d668016efd9 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 { ObjectValue } from '../model/object_value'; import { FieldPath as InternalFieldPath } from '../model/path'; -import { Query } from './reference'; +import {DocumentData, Query} from './reference'; import { AbstractUserDataWriter } from './user_data_writer'; export { AggregateType }; @@ -71,7 +71,7 @@ export type AggregateSpecData = { /** * The results of executing an aggregation query. */ -export class AggregateQuerySnapshot { +export class AggregateQuerySnapshot { /** A type string to uniquely identify instances of this class. */ readonly type = 'AggregateQuerySnapshot'; @@ -79,11 +79,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: ObjectValue ) { @@ -101,9 +101,9 @@ export class AggregateQuerySnapshot { * @returns The results of the aggregations performed over the underlying * query. */ - data(): AggregateSpecData { + data(): AggregateSpecData { return this._userDataWriter.convertValue( this._data.value - ) as AggregateSpecData; + ) as AggregateSpecData; } } diff --git a/packages/firestore/src/lite-api/query.ts b/packages/firestore/src/lite-api/query.ts index 3afa282048f..5d4bd9dee97 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,7 @@ 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 +114,7 @@ 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 +131,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 +147,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,17 +205,17 @@ 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( + return new Query( query.firestore, query.converter, queryWithAddedFilter(query._query, filter) ); } - _parse(query: Query): FieldFilter { + _parse(query: Query): FieldFilter { const reader = newUserDataReader(query.firestore); const filter = newQueryFilter( query._query, @@ -295,7 +295,7 @@ 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 +309,7 @@ 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 @@ -318,7 +318,7 @@ export class QueryCompositeFilterConstraint extends AppliableConstraint { } validateNewFilter(query._query, parsedFilter); - return new Query( + return new Query( query.firestore, query.converter, queryWithAddedFilter(query._query, parsedFilter) @@ -435,7 +435,7 @@ 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,8 +500,8 @@ export class QueryLimitConstraint extends QueryConstraint { return new QueryLimitConstraint(type, _limit, _limitType); } - _apply(query: Query): Query { - return new Query( + _apply(query: Query): Query { + return new Query( query.firestore, query.converter, queryWithLimit(query._query, this._limit, this._limitType) @@ -564,14 +564,14 @@ 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 +671,7 @@ 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 +751,10 @@ export function endAt( } /** Helper function to create a bound from a document or fields */ -function newQueryBoundFromDocOrFields( - query: Query, +function newQueryBoundFromDocOrFields( + 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 fd47405efd2..d00c2d47bb9 100644 --- a/packages/firestore/src/lite-api/reference.ts +++ b/packages/firestore/src/lite-api/reference.ts @@ -179,7 +179,7 @@ export class DocumentReference` that does not use a converter. */ - withConverter(converter: null): DocumentReference; + withConverter(converter: null): DocumentReference; withConverter( converter: FirestoreDataConverter | null ): DocumentReference { @@ -538,7 +538,7 @@ export function doc( +export function refEqual( left: DocumentReference | CollectionReference, right: DocumentReference | CollectionReference ): boolean { @@ -568,7 +568,7 @@ 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..7f20b93afa5 100644 --- a/packages/firestore/src/lite-api/reference_impl.ts +++ b/packages/firestore/src/lite-api/reference_impl.ts @@ -39,7 +39,7 @@ import { FieldPath } from './field_path'; import { validateHasExplicitOrderByForLimitToLast } from './query'; import { CollectionReference, - doc, + doc, DocumentData, DocumentReference, PartialWithFieldValue, Query, @@ -71,9 +71,9 @@ import { AbstractUserDataWriter } from './user_data_writer'; * their `set()` or fails due to invalid data originating from a `toFirestore()` * call. */ -export function applyFirestoreDataConverter( - converter: UntypedFirestoreDataConverter | null, - value: WithFieldValue | PartialWithFieldValue, +export function applyFirestoreDataConverter( + converter: UntypedFirestoreDataConverter | null, + value: WithFieldValue | PartialWithFieldValue, options?: PublicSetOptions ): PublicDocumentData { let convertedValue; @@ -120,10 +120,10 @@ 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 +131,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 +154,8 @@ 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 +163,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 +179,7 @@ export function getDocs(query: Query): Promise> { docs.reverse(); } - return new QuerySnapshot(query, docs); + return new QuerySnapshot(query, docs); }); } @@ -198,9 +198,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 +219,17 @@ 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 +269,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 +294,19 @@ 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 +353,10 @@ 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 +378,16 @@ 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 d00086740bd..c2b353dd088 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 + * `AppType` into Firestore data. * * Using the converter allows you to specify generic type arguments when * storing and retrieving objects from Firestore. @@ -80,9 +80,11 @@ import { AbstractUserDataWriter } from './user_data_writer'; */ export interface FirestoreDataConverter { /** - * 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)} + * Called by the Firestore SDK to convert a custom model object of type + * `AppType` into a plain Javascript object, `DbType` (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)}. * * The `WithFieldValue` type extends `T` to also allow FieldValues such as @@ -91,10 +93,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 + * `AppType` into a plain Javascript object, `DbType` (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`. * * The `PartialWithFieldValue` type extends `Partial` to allow * FieldValues such as {@link (arrayUnion:1)} to be used as property values. @@ -107,8 +112,9 @@ 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()`. + * Called by the Firestore SDK to convert Firestore data `DbType` into an + * object of type `AppType`. You can access your data by calling + * `snapshot.data()`. * * @param snapshot - A `QueryDocumentSnapshot` containing your data and * metadata. From 456d3e69007364d149a688005f8ff7a766f227bc Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Mon, 24 Apr 2023 11:43:16 -0400 Subject: [PATCH 3/9] finish up lite-api --- packages/firestore/src/lite-api/aggregate.ts | 35 +++- .../firestore/src/lite-api/aggregate_types.ts | 10 +- packages/firestore/src/lite-api/query.ts | 63 +++++-- packages/firestore/src/lite-api/reference.ts | 167 +++++++++++++++--- .../firestore/src/lite-api/reference_impl.ts | 124 +++++++++---- packages/firestore/src/lite-api/snapshot.ts | 51 ++++-- .../firestore/src/lite-api/transaction.ts | 44 +++-- .../src/lite-api/user_data_reader.ts | 7 +- .../firestore/src/lite-api/write_batch.ts | 48 ++--- .../firestore/test/lite/integration.test.ts | 67 +++---- 10 files changed, 457 insertions(+), 159 deletions(-) diff --git a/packages/firestore/src/lite-api/aggregate.ts b/packages/firestore/src/lite-api/aggregate.ts index fc6de2d045c..129343962c8 100644 --- a/packages/firestore/src/lite-api/aggregate.ts +++ b/packages/firestore/src/lite-api/aggregate.ts @@ -32,7 +32,7 @@ import { import { getDatastore } from './components'; import { Firestore } from './database'; import { FieldPath } from './field_path'; -import {DocumentData, Query, queryEqual} from './reference'; +import { DocumentData, Query, queryEqual } from './reference'; import { LiteUserDataWriter } from './reference_impl'; import { fieldPathFromArgument } from './user_data_reader'; @@ -50,9 +50,16 @@ 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( +export function getCount< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( query: Query -): Promise }, AppType, DbType>> { +): Promise< + AggregateQuerySnapshot<{ count: AggregateField }, AppType, DbType> +> { const countQuerySpec: { count: AggregateField } = { count: count() }; @@ -87,7 +94,13 @@ export function getCount( +export function getAggregate< + AggregateSpecType extends AggregateSpec, + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( query: Query, aggregateSpec: AggregateSpecType ): Promise> { @@ -112,13 +125,23 @@ export function getAggregate( +function convertToAggregateQuerySnapshot< + AggregateSpecType extends AggregateSpec, + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( firestore: Firestore, query: Query, aggregateResult: ObjectValue ): AggregateQuerySnapshot { const userDataWriter = new LiteUserDataWriter(firestore); - const querySnapshot = new AggregateQuerySnapshot(query, userDataWriter, aggregateResult); + const querySnapshot = new AggregateQuerySnapshot< + AggregateSpecType, + AppType, + DbType + >(query, userDataWriter, aggregateResult); return querySnapshot; } diff --git a/packages/firestore/src/lite-api/aggregate_types.ts b/packages/firestore/src/lite-api/aggregate_types.ts index d668016efd9..49fa2eaea98 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 { ObjectValue } from '../model/object_value'; import { FieldPath as InternalFieldPath } from '../model/path'; -import {DocumentData, Query} from './reference'; +import { DocumentData, Query } from './reference'; import { AbstractUserDataWriter } from './user_data_writer'; export { AggregateType }; @@ -71,7 +71,13 @@ export type AggregateSpecData = { /** * The results of executing an aggregation query. */ -export class AggregateQuerySnapshot { +export class AggregateQuerySnapshot< + AggregateSpecType extends AggregateSpec, + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +> { /** A type string to uniquely identify instances of this class. */ readonly type = 'AggregateQuerySnapshot'; diff --git a/packages/firestore/src/lite-api/query.ts b/packages/firestore/src/lite-api/query.ts index 5d4bd9dee97..a59c440a03c 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 {DocumentData, 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,7 +135,12 @@ 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( +export function query< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( query: Query, compositeFilter: QueryCompositeFilterConstraint, ...queryConstraints: QueryNonFilterConstraint[] @@ -147,12 +156,22 @@ export function query( +export function query< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( query: Query, ...queryConstraints: QueryConstraint[] ): Query; -export function query( +export function query< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( query: Query, queryConstraint: QueryCompositeFilterConstraint | QueryConstraint | undefined, ...additionalQueryConstraints: Array< @@ -205,7 +224,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 +236,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 +318,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 +334,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 +462,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 +529,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,7 +595,9 @@ 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, @@ -671,7 +704,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, diff --git a/packages/firestore/src/lite-api/reference.ts b/packages/firestore/src/lite-api/reference.ts index d00c2d47bb9..7fd583b65e5 100644 --- a/packages/firestore/src/lite-api/reference.ts +++ b/packages/firestore/src/lite-api/reference.ts @@ -110,7 +110,12 @@ export type SetOptions = * 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< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +> { /** The type of this Firestore reference. */ readonly type = 'document'; @@ -172,7 +177,14 @@ export class DocumentReference` that uses the provided converter. */ - withConverter(converter: FirestoreDataConverter): DocumentReference; + withConverter< + NewAppType = DocumentData, + NewDbType extends DocumentData = NewAppType extends DocumentData + ? NewAppType + : DocumentData + >( + converter: FirestoreDataConverter + ): DocumentReference; /** * Removes the current converter. * @@ -180,10 +192,19 @@ export class DocumentReference` that does not use a converter. */ withConverter(converter: null): DocumentReference; - withConverter( + withConverter< + NewAppType = DocumentData, + NewDbType extends DocumentData = NewAppType extends DocumentData + ? NewAppType + : DocumentData + >( converter: FirestoreDataConverter | null ): DocumentReference { - return new DocumentReference(this.firestore, converter, this._key); + return new DocumentReference( + this.firestore, + converter, + this._key + ); } } @@ -191,7 +212,12 @@ export class DocumentReference { +export class Query< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +> { /** The type of this Firestore reference. */ readonly type: 'query' | 'collection' = 'query'; @@ -231,9 +257,27 @@ export class Query` that uses the provided converter. */ - withConverter(converter: FirestoreDataConverter): Query; - withConverter(converter: FirestoreDataConverter | null): Query { - return new Query(this.firestore, converter, this._query); + withConverter< + NewAppType = DocumentData, + NewDbType extends DocumentData = NewAppType extends DocumentData + ? NewAppType + : DocumentData + >( + converter: FirestoreDataConverter + ): Query; + withConverter< + NewAppType = DocumentData, + NewDbType extends DocumentData = NewAppType extends DocumentData + ? NewAppType + : DocumentData + >( + converter: FirestoreDataConverter | null + ): Query { + return new Query( + this.firestore, + converter, + this._query + ); } } @@ -241,7 +285,12 @@ export class Query extends Query { +export class CollectionReference< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +> extends Query { /** The type of this Firestore reference. */ readonly type = 'collection'; @@ -293,7 +342,12 @@ export class CollectionReference` that uses the provided converter. */ - withConverter( + withConverter< + NewAppType = DocumentData, + NewDbType extends DocumentData = NewAppType extends DocumentData + ? NewAppType + : DocumentData + >( converter: FirestoreDataConverter ): CollectionReference; /** @@ -303,9 +357,22 @@ export class 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< + NewAppType = DocumentData, + NewDbType extends DocumentData = NewAppType extends DocumentData + ? NewAppType + : DocumentData + >( + converter: FirestoreDataConverter | null + ): CollectionReference { + return new CollectionReference( + this.firestore, + converter, + this._path + ); } } @@ -338,7 +405,12 @@ export function collection( * to a collection. * @returns The `CollectionReference` instance. */ -export function collection( +export function collection< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( reference: CollectionReference, path: string, ...pathSegments: string[] @@ -355,13 +427,26 @@ export function collection( +export function collection< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( reference: DocumentReference, path: string, ...pathSegments: string[] ): CollectionReference; -export function collection( - parent: Firestore | DocumentReference | CollectionReference, +export function collection< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + parent: + | Firestore + | DocumentReference + | CollectionReference, path: string, ...pathSegments: string[] ): CollectionReference { @@ -463,7 +548,12 @@ export function doc( * a document. * @returns The `DocumentReference` instance. */ -export function doc( +export function doc< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( reference: CollectionReference, path?: string, ...pathSegments: string[] @@ -480,13 +570,26 @@ export function doc( +export function doc< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( reference: DocumentReference, path: string, ...pathSegments: string[] ): DocumentReference; -export function doc( - parent: Firestore | CollectionReference | DocumentReference, +export function doc< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + parent: + | Firestore + | CollectionReference + | DocumentReference, path?: string, ...pathSegments: string[] ): DocumentReference { @@ -538,9 +641,18 @@ export function doc( - left: DocumentReference | CollectionReference, - right: DocumentReference | CollectionReference +export function refEqual< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + left: + | DocumentReference + | CollectionReference, + right: + | DocumentReference + | CollectionReference ): boolean { left = getModularInstance(left); right = getModularInstance(right); @@ -568,7 +680,12 @@ export function refEqual(left: Query, right: Query): boolean { +export function queryEqual< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>(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 7f20b93afa5..63dfb97d720 100644 --- a/packages/firestore/src/lite-api/reference_impl.ts +++ b/packages/firestore/src/lite-api/reference_impl.ts @@ -39,7 +39,8 @@ import { FieldPath } from './field_path'; import { validateHasExplicitOrderByForLimitToLast } from './query'; import { CollectionReference, - doc, DocumentData, + doc, + DocumentData, DocumentReference, PartialWithFieldValue, Query, @@ -71,25 +72,21 @@ import { AbstractUserDataWriter } from './user_data_writer'; * their `set()` or fails due to invalid data originating from a `toFirestore()` * call. */ -export function applyFirestoreDataConverter( +export function applyFirestoreDataConverter< + AppType, + DbType extends PublicDocumentData +>( converter: UntypedFirestoreDataConverter | null, value: WithFieldValue | PartialWithFieldValue, options?: PublicSetOptions ): PublicDocumentData { - let convertedValue; - if (converter) { - if (options && (options.merge || options.mergeFields)) { - // Cast to `any` in order to satisfy the union type constraint on - // toFirestore(). - // eslint-disable-next-line @typescript-eslint/no-explicit-any - convertedValue = (converter as any).toFirestore(value, options); - } else { - convertedValue = converter.toFirestore(value as WithFieldValue); - } - } else { - convertedValue = value as PublicDocumentData; + if (!converter) { + return value as PublicDocumentData; + } + if (options && (options.merge || options.mergeFields)) { + return converter.toFirestore(value, options); } - return convertedValue; + return converter.toFirestore(value as WithFieldValue); } export class LiteUserDataWriter extends AbstractUserDataWriter { @@ -120,10 +117,18 @@ export class LiteUserDataWriter extends AbstractUserDataWriter { * @returns A Promise resolved with a `DocumentSnapshot` containing the current * document contents. */ -export function getDoc( +export function getDoc< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( reference: DocumentReference ): Promise> { - reference = cast>(reference, DocumentReference); + reference = cast>( + reference, + DocumentReference + ); const datastore = getDatastore(reference.firestore); const userDataWriter = new LiteUserDataWriter(reference.firestore); @@ -154,7 +159,12 @@ export function getDoc(query: Query): Promise> { +export function getDocs< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>(query: Query): Promise> { query = cast>(query, Query); validateHasExplicitOrderByForLimitToLast(query._query); @@ -198,7 +208,12 @@ export function getDocs( +export function setDoc< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( reference: DocumentReference, data: WithFieldValue ): Promise; @@ -219,17 +234,30 @@ export function setDoc( +export function setDoc< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( reference: DocumentReference, data: PartialWithFieldValue, options: SetOptions ): Promise; -export function setDoc( +export function setDoc< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( reference: DocumentReference, data: PartialWithFieldValue, options?: SetOptions ): Promise { - reference = cast>(reference, DocumentReference); + reference = cast>( + reference, + DocumentReference + ); const convertedValue = applyFirestoreDataConverter( reference.converter, data, @@ -269,7 +297,12 @@ export function setDoc( +export function updateDoc< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( reference: DocumentReference, data: UpdateData ): Promise; @@ -294,19 +327,32 @@ export function updateDoc( +export function updateDoc< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( reference: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[] ): Promise; -export function updateDoc( +export function updateDoc< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( 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 +399,16 @@ export function updateDoc( - reference: DocumentReference -): Promise { - reference = cast>(reference, DocumentReference); +export function deleteDoc< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>(reference: DocumentReference): Promise { + reference = cast>( + reference, + DocumentReference + ); const datastore = getDatastore(reference.firestore); return invokeCommitRpc(datastore, [ new DeleteMutation(reference._key, Precondition.none()) @@ -378,11 +430,19 @@ export function deleteDoc( +export function addDoc< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( reference: CollectionReference, data: WithFieldValue ): Promise> { - reference = cast>(reference, CollectionReference); + reference = cast>( + reference, + CollectionReference + ); const docRef = doc(reference); const convertedValue = applyFirestoreDataConverter( diff --git a/packages/firestore/src/lite-api/snapshot.ts b/packages/firestore/src/lite-api/snapshot.ts index c2b353dd088..7e95fec8c91 100644 --- a/packages/firestore/src/lite-api/snapshot.ts +++ b/packages/firestore/src/lite-api/snapshot.ts @@ -78,7 +78,12 @@ import { AbstractUserDataWriter } from './user_data_writer'; * } * ``` */ -export interface FirestoreDataConverter { +export interface FirestoreDataConverter< + AppType, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +> { /** * Called by the Firestore SDK to convert a custom model object of type * `AppType` into a plain Javascript object, `DbType` (suitable for writing @@ -131,7 +136,12 @@ export interface FirestoreDataConverter { +export class DocumentSnapshot< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +> { // Note: This class is stripped down version of the DocumentSnapshot in // the legacy SDK. The changes are: // - No support for SnapshotMetadata. @@ -193,7 +203,9 @@ export class DocumentSnapshot extends DocumentSnapshot { +export class QueryDocumentSnapshot< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +> extends DocumentSnapshot { /** * Retrieves all fields in the document as an `Object`. * @@ -251,7 +268,12 @@ export class QueryDocumentSnapshot { +export class QuerySnapshot< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +> { /** * The query on which you called {@link getDocs} in order to get this * `QuerySnapshot`. @@ -260,14 +282,14 @@ export class QuerySnapshot, - 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]; } @@ -289,7 +311,7 @@ export class QuerySnapshot) => void, + callback: (result: QueryDocumentSnapshot) => void, thisArg?: unknown ): void { this._docs.forEach(callback, thisArg); @@ -303,9 +325,14 @@ export class QuerySnapshot( - left: DocumentSnapshot | QuerySnapshot, - right: DocumentSnapshot | QuerySnapshot +export function snapshotEqual< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + 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 a1724ee0960..17b55a98e13 100644 --- a/packages/firestore/src/lite-api/transaction.ts +++ b/packages/firestore/src/lite-api/transaction.ts @@ -87,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 => { @@ -96,7 +98,7 @@ export class Transaction { } const doc = docs[0]; if (doc.isFoundDocument()) { - return new DocumentSnapshot( + return new DocumentSnapshot( this._firestore, userDataWriter, doc.key, @@ -104,7 +106,7 @@ export class Transaction { ref.converter ); } else if (doc.isNoDocument()) { - return new DocumentSnapshot( + return new DocumentSnapshot( this._firestore, userDataWriter, ref._key, @@ -128,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. @@ -141,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); @@ -181,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 @@ -197,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 { @@ -247,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 d384c6e3a79..6f2fcd730f3 100644 --- a/packages/firestore/src/lite-api/user_data_reader.ts +++ b/packages/firestore/src/lite-api/user_data_reader.ts @@ -76,7 +76,12 @@ const RESERVED_FIELD_REGEX = /^__.*__$/; * An untyped Firestore Data Converter interface that is shared between the * lite, firestore-exp and classic SDK. */ -export interface UntypedFirestoreDataConverter { +export interface UntypedFirestoreDataConverter< + AppType, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +> { toFirestore(modelObject: WithFieldValue): WithFieldValue; toFirestore( modelObject: PartialWithFieldValue, diff --git a/packages/firestore/src/lite-api/write_batch.ts b/packages/firestore/src/lite-api/write_batch.ts index e626646f3f7..686395b0c92 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,12 @@ export class WriteBatch { } } -export function validateReference( - documentRef: DocumentReference | Compat>, +export function validateReference( + documentRef: + | DocumentReference + | Compat>, firestore: Firestore -): DocumentReference { +): DocumentReference { documentRef = getModularInstance(documentRef); if (documentRef.firestore !== firestore) { @@ -254,7 +262,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..52eee3ec5d6 100644 --- a/packages/firestore/test/lite/integration.test.ts +++ b/packages/firestore/test/lite/integration.test.ts @@ -79,6 +79,7 @@ import { } from '../../src/lite-api/reference_impl'; import { snapshotEqual, + FirestoreDataConverter, QuerySnapshot, QueryDocumentSnapshot } from '../../src/lite-api/snapshot'; @@ -428,26 +429,28 @@ describe('getDoc()', () => { * DocumentReference-based mutation API. */ interface MutationTester { - set( - documentRef: DocumentReference, - data: WithFieldValue - ): Promise; - set( - documentRef: DocumentReference, - data: PartialWithFieldValue, + set( + documentRef: DocumentReference, + data: PartialWithFieldValue, options: SetOptions ): Promise; - update( - documentRef: DocumentReference, - data: UpdateData + set( + documentRef: DocumentReference, + data: WithFieldValue + ): Promise; + 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 }; }, From 8d5257f1810323271bbab922a4215ac64e9d7d60 Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Mon, 24 Apr 2023 11:49:39 -0400 Subject: [PATCH 4/9] cleanup: --- packages/firestore/src/lite-api/aggregate.ts | 8 +++++--- packages/firestore/src/lite-api/reference_impl.ts | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/firestore/src/lite-api/aggregate.ts b/packages/firestore/src/lite-api/aggregate.ts index 129343962c8..13981e7246b 100644 --- a/packages/firestore/src/lite-api/aggregate.ts +++ b/packages/firestore/src/lite-api/aggregate.ts @@ -208,9 +208,11 @@ 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 +>( + left: AggregateQuerySnapshot, + right: AggregateQuerySnapshot ): boolean { return ( queryEqual(left.query, right.query) && deepEqual(left.data(), right.data()) diff --git a/packages/firestore/src/lite-api/reference_impl.ts b/packages/firestore/src/lite-api/reference_impl.ts index 63dfb97d720..7c8ceb93a24 100644 --- a/packages/firestore/src/lite-api/reference_impl.ts +++ b/packages/firestore/src/lite-api/reference_impl.ts @@ -64,8 +64,8 @@ import { import { AbstractUserDataWriter } from './user_data_writer'; /** - * Converts custom model object of type T into `DocumentData` by applying the - * converter if it exists. + * Converts custom model object of type `AppType` into `DocumentData` by + * applying the converter if it exists. * * This function is used when converting user objects to `DocumentData` * because we want to provide the user with a more specific error message if From f921d2511e3a99674a7ad5c78e9d9fbf231c9c64 Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Mon, 24 Apr 2023 12:43:59 -0400 Subject: [PATCH 5/9] do normal api --- packages/firestore/src/api/aggregate.ts | 20 +- packages/firestore/src/api/reference_impl.ts | 257 +++++++++++++------ packages/firestore/src/api/snapshot.ts | 76 +++--- packages/firestore/src/api/transaction.ts | 6 +- 4 files changed, 222 insertions(+), 137 deletions(-) diff --git a/packages/firestore/src/api/aggregate.ts b/packages/firestore/src/api/aggregate.ts index 3ced0c8b292..74d1c68bbfb 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'; @@ -57,9 +57,7 @@ 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(query: Query): Promise }, AppType, DbType>> { const countQuerySpec: { count: AggregateField } = { count: count() }; @@ -101,10 +99,7 @@ export function getCountFromServer( * ``` * @internal TODO (sum/avg) remove when public */ -export function getAggregateFromServer( - query: Query, - aggregateSpec: T -): Promise> { +export function getAggregateFromServer(query: Query, aggregateSpec: AggregateSpecType): Promise> { const firestore = cast(query.firestore, Firestore); const client = ensureFirestoreConfigured(firestore); @@ -133,16 +128,11 @@ export function getAggregateFromServer( * @param aggregateResult Core aggregation result * @internal */ -function convertToAggregateQuerySnapshot( - firestore: Firestore, - query: Query, - aggregateResult: ObjectValue -): AggregateQuerySnapshot { +function convertToAggregateQuerySnapshot(firestore: Firestore, query: Query, aggregateResult: ObjectValue): AggregateQuerySnapshot { const userDataWriter = new ExpUserDataWriter(firestore); - const querySnapshot = new AggregateQuerySnapshot( + return new AggregateQuerySnapshot( 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..25316acb056 100644 --- a/packages/firestore/src/api/reference_impl.ts +++ b/packages/firestore/src/api/reference_impl.ts @@ -40,7 +40,7 @@ import { FieldPath } from '../lite-api/field_path'; import { validateHasExplicitOrderByForLimitToLast } from '../lite-api/query'; import { CollectionReference, - doc, + doc, DocumentData, DocumentReference, PartialWithFieldValue, Query, @@ -91,10 +91,8 @@ 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,10 +124,15 @@ 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< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + reference: DocumentReference +): Promise> { + reference = cast>(reference, DocumentReference); const firestore = cast(reference.firestore, Firestore); const client = ensureFirestoreConfigured(firestore); const userDataWriter = new ExpUserDataWriter(firestore); @@ -157,10 +160,15 @@ 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< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + reference: DocumentReference +): Promise> { + reference = cast>(reference, DocumentReference); const firestore = cast(reference.firestore, Firestore); const client = ensureFirestoreConfigured(firestore); @@ -179,8 +187,13 @@ 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< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>(query: Query): Promise> { + query = cast>(query, Query); const firestore = cast(query.firestore, Firestore); const client = ensureFirestoreConfigured(firestore); const userDataWriter = new ExpUserDataWriter(firestore); @@ -201,10 +214,15 @@ 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< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + query: Query +): Promise> { + query = cast>(query, Query); const firestore = cast(query.firestore, Firestore); const client = ensureFirestoreConfigured(firestore); const userDataWriter = new ExpUserDataWriter(firestore); @@ -220,10 +238,15 @@ 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< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : 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 +267,14 @@ 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< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + reference: DocumentReference, + data: WithFieldValue ): Promise; /** * Writes to the document referred to by the specified `DocumentReference`. If @@ -259,22 +287,32 @@ 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< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + reference: DocumentReference, + data: PartialWithFieldValue, options: SetOptions ): Promise; -export function setDoc( - reference: DocumentReference, - data: PartialWithFieldValue, +export function setDoc< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + 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 +341,14 @@ 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< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + reference: DocumentReference, + data: UpdateData ): Promise; /** * Updates fields in the document referred to by the specified @@ -322,19 +365,29 @@ 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< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + reference: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[] ): Promise; -export function updateDoc( - reference: DocumentReference, - fieldOrUpdateData: string | FieldPath | UpdateData, +export function updateDoc< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + reference: DocumentReference, + 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 +429,13 @@ 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< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + reference: DocumentReference ): Promise { const firestore = cast(reference.firestore, Firestore); const mutations = [new DeleteMutation(reference._key, Precondition.none())]; @@ -394,10 +452,15 @@ 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< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + reference: CollectionReference, + data: WithFieldValue +): Promise> { const firestore = cast(reference.firestore, Firestore); const docRef = doc(reference); @@ -441,10 +504,15 @@ export interface Unsubscribe { * @returns An unsubscribe function that can be called to cancel * the snapshot listener. */ -export function onSnapshot( - reference: DocumentReference, +export function onSnapshot< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + reference: DocumentReference, observer: { - next?: (snapshot: DocumentSnapshot) => void; + next?: (snapshot: DocumentSnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; } @@ -463,11 +531,16 @@ export function onSnapshot( * @returns An unsubscribe function that can be called to cancel * the snapshot listener. */ -export function onSnapshot( - reference: DocumentReference, +export function onSnapshot< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + reference: DocumentReference, options: SnapshotListenOptions, observer: { - next?: (snapshot: DocumentSnapshot) => void; + next?: (snapshot: DocumentSnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; } @@ -490,9 +563,14 @@ 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< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + reference: DocumentReference, + onNext: (snapshot: DocumentSnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void ): Unsubscribe; @@ -515,10 +593,15 @@ export function onSnapshot( * @returns An unsubscribe function that can be called to cancel * the snapshot listener. */ -export function onSnapshot( - reference: DocumentReference, +export function onSnapshot< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + reference: DocumentReference, options: SnapshotListenOptions, - onNext: (snapshot: DocumentSnapshot) => void, + onNext: (snapshot: DocumentSnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void ): Unsubscribe; @@ -536,10 +619,15 @@ export function onSnapshot( * @returns An unsubscribe function that can be called to cancel * the snapshot listener. */ -export function onSnapshot( - query: Query, +export function onSnapshot< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + query: Query, observer: { - next?: (snapshot: QuerySnapshot) => void; + next?: (snapshot: QuerySnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; } @@ -559,11 +647,16 @@ export function onSnapshot( * @returns An unsubscribe function that can be called to cancel * the snapshot listener. */ -export function onSnapshot( - query: Query, +export function onSnapshot< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + query: Query, options: SnapshotListenOptions, observer: { - next?: (snapshot: QuerySnapshot) => void; + next?: (snapshot: QuerySnapshot) => void; error?: (error: FirestoreError) => void; complete?: () => void; } @@ -587,9 +680,14 @@ 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< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + query: Query, + onNext: (snapshot: QuerySnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void ): Unsubscribe; @@ -613,10 +711,15 @@ export function onSnapshot( * @returns An unsubscribe function that can be called to cancel * the snapshot listener. */ -export function onSnapshot( - query: Query, +export function onSnapshot< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + query: Query, options: SnapshotListenOptions, - onNext: (snapshot: QuerySnapshot) => void, + onNext: (snapshot: QuerySnapshot) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void ): Unsubscribe; @@ -776,11 +879,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 +891,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..215802bf901 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 + * `AppType` into Firestore data. * * Using the converter allows you to specify generic type arguments when * storing and retrieving objects from Firestore. @@ -58,7 +58,7 @@ import { SnapshotListenOptions } from './reference_impl'; * } * } * - * const postConverter = { + * const postConverter: FirestoreDataConverter = { * toFirestore(post: WithFieldValue): DocumentData { * return {title: post.title, author: post.author}; * }, @@ -83,8 +83,7 @@ import { SnapshotListenOptions } from './reference_impl'; * } * ``` */ -export interface FirestoreDataConverter - extends LiteFirestoreDataConverter { +export interface FirestoreDataConverter 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 +93,7 @@ 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 +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 @@ -120,9 +119,9 @@ export interface FirestoreDataConverter * @param options - The `SnapshotOptions` from the initial call to `data()`. */ fromFirestore( - snapshot: QueryDocumentSnapshot, + snapshot: QueryDocumentSnapshot, options?: SnapshotOptions - ): T; + ): AppType; } /** @@ -200,12 +199,12 @@ 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 { /** 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 @@ -232,9 +231,7 @@ export interface DocumentChange { * access will return 'undefined'. You can use the `exists()` method to * explicitly verify a document's existence. */ -export class DocumentSnapshot< - T = DocumentData -> extends LiteDocumentSnapshot { +export class DocumentSnapshot extends LiteDocumentSnapshot { private readonly _firestoreImpl: Firestore; /** @@ -250,7 +247,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 +257,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 +275,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 = {}): AppType | undefined { if (!this._document) { return undefined; } else if (this._converter) { @@ -297,7 +294,7 @@ export class DocumentSnapshot< return this._userDataWriter.convertValue( this._document.data.value, options.serverTimestamps - ) as T; + ) as AppType; } } @@ -346,9 +343,7 @@ export class DocumentSnapshot< * `exists` property will always be true and `data()` will never return * 'undefined'. */ -export class QueryDocumentSnapshot< - T = DocumentData -> extends DocumentSnapshot { +export class QueryDocumentSnapshot extends DocumentSnapshot { /** * Retrieves all fields in the document as an `Object`. * @@ -362,8 +357,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 = {}): AppType { + return super.data(options) as AppType; } } @@ -374,7 +369,7 @@ export class QueryDocumentSnapshot< * number of documents can be determined via the `empty` and `size` * properties. */ -export class QuerySnapshot { +export class QuerySnapshot { /** * Metadata about this snapshot, concerning its source and if it has local * modifications. @@ -385,16 +380,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 +400,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 +424,13 @@ 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 +454,7 @@ 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 +478,10 @@ export class QuerySnapshot { } /** Calculates the array of `DocumentChange`s for a given `ViewSnapshot`. */ -export function changesFromSnapshot( - querySnapshot: QuerySnapshot, +export function changesFromSnapshot( + 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 +500,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 +528,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,10 +583,7 @@ 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 -): boolean { +export function snapshotEqual(left: DocumentSnapshot | QuerySnapshot, right: DocumentSnapshot | QuerySnapshot): boolean { if (left instanceof DocumentSnapshot && right instanceof DocumentSnapshot) { return ( left._firestore === right._firestore && diff --git a/packages/firestore/src/api/transaction.ts b/packages/firestore/src/api/transaction.ts index a70cfba231d..2bb7954d0d2 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,8 @@ 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) From e14de0b5e661b351fd0e1f3263b46d5b89ad8a14 Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Mon, 24 Apr 2023 12:52:27 -0400 Subject: [PATCH 6/9] firestore[-lite].api.md update --- common/api-review/firestore-lite.api.md | 132 +++++++++--------- common/api-review/firestore.api.md | 170 ++++++++++++------------ 2 files changed, 149 insertions(+), 153 deletions(-) diff --git a/common/api-review/firestore-lite.api.md b/common/api-review/firestore-lite.api.md index 35802afacb7..b370ddb8c99 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,48 +96,46 @@ 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 { - [field: string]: any; -} +export type DocumentData = Record; // @public 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(): AppType | undefined; + exists(): this is QueryDocumentSnapshot; get(fieldPath: string | FieldPath): any; get id(): string; - get ref(): DocumentReference; + get ref(): DocumentReference; } export { EmulatorMockTokenOptions } @@ -173,10 +171,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): AppType; + toFirestore(modelObject: WithFieldValue): WithFieldValue; + toFirestore(modelObject: PartialWithFieldValue, options: SetOptions): PartialWithFieldValue; } // @public @@ -202,15 +200,15 @@ export class GeoPoint { } // @public -export function getCount(query: Query): Promise(query: Query): Promise; -}>>; +}, AppType, DbType>>; // @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 +253,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 +282,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(): AppType; } // @public @@ -295,7 +293,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 +317,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 +331,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 +340,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 +363,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 +403,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 +425,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 +444,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 53e8e60cab8..ac569497641 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; @@ -131,34 +131,32 @@ export interface DocumentChange { export type DocumentChangeType = 'added' | 'removed' | 'modified'; // @public -export interface DocumentData { - [field: string]: any; -} +export type DocumentData = Record; // @public 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): AppType | 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 } @@ -203,10 +201,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): AppType; + toFirestore(modelObject: WithFieldValue): WithFieldValue; + toFirestore(modelObject: PartialWithFieldValue, options: SetOptions): PartialWithFieldValue; } // @public @@ -246,27 +244,27 @@ export class GeoPoint { } // @public -export function getCountFromServer(query: Query): Promise(query: Query): Promise; -}>>; +}, AppType, DbType>>; // @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; @@ -377,44 +375,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: { @@ -490,20 +488,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 { @@ -519,9 +517,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): AppType; } // @public @@ -530,7 +528,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 { @@ -554,13 +552,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; } @@ -570,7 +568,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; @@ -579,10 +577,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; @@ -601,7 +599,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 { @@ -661,12 +659,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 @@ -688,10 +686,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; @@ -710,11 +708,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 b34e3404c516e2384c53abada57fc356aeab6a57 Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Mon, 24 Apr 2023 13:01:49 -0400 Subject: [PATCH 7/9] cleanup --- packages/firestore/src/api/aggregate.ts | 34 ++++++++-- packages/firestore/src/api/reference_impl.ts | 49 +++++++++----- packages/firestore/src/api/snapshot.ts | 70 +++++++++++++++----- packages/firestore/src/api/transaction.ts | 11 ++- packages/firestore/src/lite-api/snapshot.ts | 2 +- 5 files changed, 126 insertions(+), 40 deletions(-) diff --git a/packages/firestore/src/api/aggregate.ts b/packages/firestore/src/api/aggregate.ts index 74d1c68bbfb..4a98e18bb96 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, DocumentData, 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'; @@ -57,7 +57,16 @@ export { * retrieved from `snapshot.data().count`, where `snapshot` is the * `AggregateQuerySnapshot` to which the returned Promise resolves. */ -export function getCountFromServer(query: Query): Promise }, AppType, DbType>> { +export function getCountFromServer< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + query: Query +): Promise< + AggregateQuerySnapshot<{ count: AggregateField }, AppType, DbType> +> { const countQuerySpec: { count: AggregateField } = { count: count() }; @@ -99,7 +108,16 @@ export function getCountFromServer(query: Query, aggregateSpec: AggregateSpecType): Promise> { +export function getAggregateFromServer< + AggregateSpecType extends AggregateSpec, + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + query: Query, + aggregateSpec: AggregateSpecType +): Promise> { const firestore = cast(query.firestore, Firestore); const client = ensureFirestoreConfigured(firestore); @@ -128,7 +146,15 @@ export function getAggregateFromServer(firestore: Firestore, query: Query, aggregateResult: ObjectValue): AggregateQuerySnapshot { +function convertToAggregateQuerySnapshot< + AggregateSpecType extends AggregateSpec, + AppType, + DbType extends DocumentData +>( + firestore: Firestore, + query: Query, + aggregateResult: ObjectValue +): AggregateQuerySnapshot { const userDataWriter = new ExpUserDataWriter(firestore); return new AggregateQuerySnapshot( query, diff --git a/packages/firestore/src/api/reference_impl.ts b/packages/firestore/src/api/reference_impl.ts index 25316acb056..6f24f9a69ab 100644 --- a/packages/firestore/src/api/reference_impl.ts +++ b/packages/firestore/src/api/reference_impl.ts @@ -40,7 +40,8 @@ import { FieldPath } from '../lite-api/field_path'; import { validateHasExplicitOrderByForLimitToLast } from '../lite-api/query'; import { CollectionReference, - doc, DocumentData, + doc, + DocumentData, DocumentReference, PartialWithFieldValue, Query, @@ -91,8 +92,18 @@ 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< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + reference: DocumentReference +): Promise> { + reference = cast>( + reference, + DocumentReference + ); const firestore = cast(reference.firestore, Firestore); const client = ensureFirestoreConfigured(firestore); @@ -132,7 +143,10 @@ export function getDocFromCache< >( reference: DocumentReference ): Promise> { - reference = cast>(reference, DocumentReference); + reference = cast>( + reference, + DocumentReference + ); const firestore = cast(reference.firestore, Firestore); const client = ensureFirestoreConfigured(firestore); const userDataWriter = new ExpUserDataWriter(firestore); @@ -168,7 +182,10 @@ export function getDocFromServer< >( reference: DocumentReference ): Promise> { - reference = cast>(reference, DocumentReference); + reference = cast>( + reference, + DocumentReference + ); const firestore = cast(reference.firestore, Firestore); const client = ensureFirestoreConfigured(firestore); @@ -219,9 +236,7 @@ export function getDocsFromCache< DbType extends DocumentData = AppType extends DocumentData ? AppType : DocumentData ->( - query: Query -): Promise> { +>(query: Query): Promise> { query = cast>(query, Query); const firestore = cast(query.firestore, Firestore); const client = ensureFirestoreConfigured(firestore); @@ -243,9 +258,7 @@ export function getDocsFromServer< DbType extends DocumentData = AppType extends DocumentData ? AppType : DocumentData ->( - query: Query -): Promise> { +>(query: Query): Promise> { query = cast>(query, Query); const firestore = cast(query.firestore, Firestore); const client = ensureFirestoreConfigured(firestore); @@ -307,7 +320,10 @@ export function setDoc< data: PartialWithFieldValue, options?: SetOptions ): Promise { - reference = cast>(reference, DocumentReference); + reference = cast>( + reference, + DocumentReference + ); const firestore = cast(reference.firestore, Firestore); const convertedValue = applyFirestoreDataConverter( @@ -387,7 +403,10 @@ export function updateDoc< value?: unknown, ...moreFieldsAndValues: unknown[] ): Promise { - reference = cast>(reference, DocumentReference); + reference = cast>( + reference, + DocumentReference + ); const firestore = cast(reference.firestore, Firestore); const dataReader = newUserDataReader(firestore); @@ -434,9 +453,7 @@ export function deleteDoc< DbType extends DocumentData = AppType extends DocumentData ? AppType : DocumentData ->( - reference: DocumentReference -): Promise { +>(reference: DocumentReference): Promise { const firestore = cast(reference.firestore, Firestore); const mutations = [new DeleteMutation(reference._key, Precondition.none())]; return executeWrite(firestore, mutations); diff --git a/packages/firestore/src/api/snapshot.ts b/packages/firestore/src/api/snapshot.ts index 215802bf901..efe71735df4 100644 --- a/packages/firestore/src/api/snapshot.ts +++ b/packages/firestore/src/api/snapshot.ts @@ -83,12 +83,18 @@ import { SnapshotListenOptions } from './reference_impl'; * } * ``` */ -export interface FirestoreDataConverter extends LiteFirestoreDataConverter { +export interface FirestoreDataConverter< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : 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 + * `AppType` into a plain JavaScript object, `DbType` (suitable for writing + * directly to the Firestore database). 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. @@ -96,10 +102,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 + * `AppType` into a plain JavaScript object, `DbType` (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`. * * The `PartialWithFieldValue` type extends `Partial` to allow * FieldValues such as {@link (arrayUnion:1)} to be used as property values. @@ -113,7 +120,8 @@ export interface FirestoreDataConverter { +export interface DocumentChange< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +> { /** The type of change ('added', 'modified', or 'removed'). */ readonly type: DocumentChangeType; @@ -231,7 +244,12 @@ export interface DocumentChange extends LiteDocumentSnapshot { +export class DocumentSnapshot< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +> extends LiteDocumentSnapshot { private readonly _firestoreImpl: Firestore; /** @@ -343,7 +361,12 @@ export class DocumentSnapshot extends DocumentSnapshot { +export class QueryDocumentSnapshot< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +> extends DocumentSnapshot { /** * Retrieves all fields in the document as an `Object`. * @@ -369,7 +392,12 @@ export class QueryDocumentSnapshot { +export class QuerySnapshot< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +> { /** * Metadata about this snapshot, concerning its source and if it has local * modifications. @@ -454,7 +482,9 @@ export class QuerySnapshot> { + docChanges( + options: SnapshotListenOptions = {} + ): Array> { const includeMetadataChanges = !!options.includeMetadataChanges; if (includeMetadataChanges && this._snapshot.excludesMetadataChanges) { @@ -583,7 +613,15 @@ 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): boolean { +export function snapshotEqual< + AppType = DocumentData, + DbType extends DocumentData = AppType extends DocumentData + ? AppType + : DocumentData +>( + left: DocumentSnapshot | QuerySnapshot, + right: DocumentSnapshot | QuerySnapshot +): boolean { if (left instanceof DocumentSnapshot && right instanceof DocumentSnapshot) { return ( left._firestore === right._firestore && diff --git a/packages/firestore/src/api/transaction.ts b/packages/firestore/src/api/transaction.ts index 2bb7954d0d2..cac887d1309 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 {DocumentData, 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,13 @@ 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/lite-api/snapshot.ts b/packages/firestore/src/lite-api/snapshot.ts index 7e95fec8c91..9588ac0a0f0 100644 --- a/packages/firestore/src/lite-api/snapshot.ts +++ b/packages/firestore/src/lite-api/snapshot.ts @@ -56,7 +56,7 @@ import { AbstractUserDataWriter } from './user_data_writer'; * } * } * - * const postConverter = { + * const postConverter: FirestoreDataConverter = { * toFirestore(post: WithFieldValue): DocumentData { * return {title: post.title, author: post.author}; * }, From d075807b1e7428de391bb3bb47297fa37f0048ce Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Mon, 24 Apr 2023 14:27:08 -0400 Subject: [PATCH 8/9] yarn docgen devsite --- .../firestore_.aggregatequerysnapshot.md | 10 +- .../firestore_.collectionreference.md | 18 +- docs-devsite/firestore_.documentchange.md | 6 +- docs-devsite/firestore_.documentdata.md | 19 -- docs-devsite/firestore_.documentreference.md | 20 +- docs-devsite/firestore_.documentsnapshot.md | 14 +- .../firestore_.firestoredataconverter.md | 36 +-- docs-devsite/firestore_.md | 220 +++++++++--------- 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 +- docs-devsite/firestore_lite.documentdata.md | 19 -- .../firestore_lite.documentreference.md | 20 +- .../firestore_lite.documentsnapshot.md | 14 +- .../firestore_lite.firestoredataconverter.md | 36 +-- docs-devsite/firestore_lite.md | 140 +++++------ 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 +-- 25 files changed, 389 insertions(+), 407 deletions(-) delete mode 100644 docs-devsite/firestore_.documentdata.md delete mode 100644 docs-devsite/firestore_lite.documentdata.md diff --git a/docs-devsite/firestore_.aggregatequerysnapshot.md b/docs-devsite/firestore_.aggregatequerysnapshot.md index 1cf63b5db8b..0c0e77f5870 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)<AppType, DbType> | 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..80c60e2fbe8 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)<AppType, DbType> ## 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_.md#documentdata), [DocumentData](./firestore_.md#documentdata)> \| 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)<NewAppType, NewDbType> | Converts objects to and from Firestore. | Returns: -[CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<U> +[CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<NewAppType, NewDbType> 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_.md#documentdata), [DocumentData](./firestore_.md#documentdata)> A `CollectionReference` that does not use a converter. diff --git a/docs-devsite/firestore_.documentchange.md b/docs-devsite/firestore_.documentchange.md index afef795956d..1c4f175983e 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)<AppType, DbType> | 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_.documentdata.md b/docs-devsite/firestore_.documentdata.md deleted file mode 100644 index 09b5eb64b48..00000000000 --- a/docs-devsite/firestore_.documentdata.md +++ /dev/null @@ -1,19 +0,0 @@ -Project: /docs/reference/js/_project.yaml -Book: /docs/reference/_book.yaml -page_type: reference - -{% comment %} -DO NOT EDIT THIS FILE! -This is generated by the JS SDK team, and any local changes will be -overwritten. Changes should be made in the source code at -https://github.com/firebase/firebase-js-sdk -{% endcomment %} - -# DocumentData interface -Document data (for use with [setDoc()](./firestore_lite.md#setdoc)) consists of fields mapped to values. - -Signature: - -```typescript -export declare interface DocumentData -``` diff --git a/docs-devsite/firestore_.documentreference.md b/docs-devsite/firestore_.documentreference.md index 16dff93b9c8..da8b3168ef7 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)<AppType, DbType> \| 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)<AppType, DbType> | 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)<NewAppType, NewDbType> | Converts objects to and from Firestore. | Returns: -[DocumentReference](./firestore_.documentreference.md#documentreference_class)<U> +[DocumentReference](./firestore_.documentreference.md#documentreference_class)<NewAppType, NewDbType> 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_.md#documentdata), [DocumentData](./firestore_.md#documentdata)> A `DocumentReference` that does not use a converter. diff --git a/docs-devsite/firestore_.documentsnapshot.md b/docs-devsite/firestore_.documentsnapshot.md index 3ac2ec7dcb2..582f6f8699d 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)<AppType, DbType> | 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)<AppType, DbType> ## DocumentSnapshot.get() diff --git a/docs-devsite/firestore_.firestoredataconverter.md b/docs-devsite/firestore_.firestoredataconverter.md index f7d80ac4a13..0a6199ae53c 100644 --- a/docs-devsite/firestore_.firestoredataconverter.md +++ b/docs-devsite/firestore_.firestoredataconverter.md @@ -10,89 +10,89 @@ 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 `AppType` into Firestore data. Using the converter allows you to specify generic type arguments when storing and retrieving objects from Firestore. Signature: ```typescript -export declare interface FirestoreDataConverter +export declare interface FirestoreDataConverter ``` ## Methods | Method | Description | | --- | --- | -| [fromFirestore(snapshot, options)](./firestore_.firestoredataconverter.md#firestoredataconverterfromfirestore) | 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). | -| [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 AppType. You can access your data by calling: snapshot.data(options). | +| [toFirestore(modelObject)](./firestore_.firestoredataconverter.md#firestoredataconvertertofirestore) | Called by the Firestore SDK to convert a custom model object of type AppType into a plain JavaScript object, DbType (suitable for writing directly to the Firestore database). To use set() with merge and mergeFields, toFirestore() must be defined with PartialWithFieldValue\`.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 AppType into a plain JavaScript object, DbType (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. | ## 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 `AppType`. You can access your data by calling: `snapshot.data(options)`. Signature: ```typescript -fromFirestore(snapshot: QueryDocumentSnapshot, options?: SnapshotOptions): T; +fromFirestore(snapshot: QueryDocumentSnapshot, options?: SnapshotOptions): AppType; ``` ### 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)<DbType, DbType> | A QueryDocumentSnapshot containing your data and metadata. | | options | [SnapshotOptions](./firestore_.snapshotoptions.md#snapshotoptions_interface) | The SnapshotOptions from the initial call to data(). | Returns: -T +AppType ## 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 `AppType` into a plain JavaScript object, `DbType` (suitable for writing directly to the Firestore database). 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. 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)<AppType> | | Returns: -[DocumentData](./firestore_.documentdata.md#documentdata_interface) +[WithFieldValue](./firestore_.md#withfieldvalue)<DbType> ## 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_.md#setdoc), and with `merge:true` or `mergeFields`. +Called by the Firestore SDK to convert a custom model object of type `AppType` into a plain JavaScript object, `DbType` (suitable for writing directly to the Firestore database). 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. 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)<AppType> | | | options | [SetOptions](./firestore_.md#setoptions) | | Returns: -[DocumentData](./firestore_.documentdata.md#documentdata_interface) +[PartialWithFieldValue](./firestore_.md#partialwithfieldvalue)<DbType> ### Example @@ -106,7 +106,7 @@ class Post { } } -const postConverter = { +const postConverter: FirestoreDataConverter = { toFirestore(post: WithFieldValue): DocumentData { return {title: post.title, author: post.author}; }, diff --git a/docs-devsite/firestore_.md b/docs-devsite/firestore_.md index 3fc6c253769..277da95de94 100644 --- a/docs-devsite/firestore_.md +++ b/docs-devsite/firestore_.md @@ -148,8 +148,7 @@ https://github.com/firebase/firebase-js-sdk | --- | --- | | [AggregateSpec](./firestore_.aggregatespec.md#aggregatespec_interface) | Specifies a set of aggregations and their aliases. | | [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. | -| [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 AppType into Firestore data.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. | @@ -185,6 +184,7 @@ https://github.com/firebase/firebase-js-sdk | [AggregateSpecData](./firestore_.md#aggregatespecdata) | A type whose keys are taken from an AggregateSpec, and whose values are the result of the aggregation performed by the corresponding AggregateField from the input AggregateSpec. | | [ChildUpdateFields](./firestore_.md#childupdatefields) | Helper for calculating the nested fields for a given type T1. This is needed to distribute union types such as undefined | {...} (happens for optional props) or {a: A} | {b: B}.In this use case, V is used to distribute the union types of T[K] on Record, since T[K] is evaluated as an expression and not distributed.See https://www.typescriptlang.org/docs/handbook/advanced-types.html\#distributive-conditional-types | | [DocumentChangeType](./firestore_.md#documentchangetype) | The type of a DocumentChange may be 'added', 'removed', or 'modified'. | +| [DocumentData](./firestore_.md#documentdata) | Document data (for use with [setDoc()](./firestore_lite.md#setdoc)). Must be an object with string keys. | | [FirestoreErrorCode](./firestore_.md#firestoreerrorcode) | The set of Firestore status codes. The codes are the same at the ones exposed by gRPC here: https://github.com/grpc/grpc/blob/master/doc/statuscodes.mdPossible values: - 'cancelled': The operation was cancelled (typically by the caller). - 'unknown': Unknown error or an error from a different error domain. - 'invalid-argument': Client specified an invalid argument. Note that this differs from 'failed-precondition'. 'invalid-argument' indicates arguments that are problematic regardless of the state of the system (e.g. an invalid field name). - 'deadline-exceeded': Deadline expired before operation could complete. For operations that change the state of the system, this error may be returned even if the operation has completed successfully. For example, a successful response from a server could have been delayed long enough for the deadline to expire. - 'not-found': Some requested document was not found. - 'already-exists': Some document that we attempted to create already exists. - 'permission-denied': The caller does not have permission to execute the specified operation. - 'resource-exhausted': Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space. - 'failed-precondition': Operation was rejected because the system is not in a state required for the operation's execution. - 'aborted': The operation was aborted, typically due to a concurrency issue like transaction aborts, etc. - 'out-of-range': Operation was attempted past the valid range. - 'unimplemented': Operation is not implemented or not supported/enabled. - 'internal': Internal errors. Means some invariants expected by underlying system has been broken. If you see one of these errors, something is very broken. - 'unavailable': The service is currently unavailable. This is most likely a transient condition and may be corrected by retrying with a backoff. - 'data-loss': Unrecoverable data loss or corruption. - 'unauthenticated': The request does not have valid authentication credentials for the operation. | | [FirestoreLocalCache](./firestore_.md#firestorelocalcache) | Union type from all supported SDK cache layer. | | [MemoryGarbageCollector](./firestore_.md#memorygarbagecollector) | Union type from all support gabage collectors for memory local cache. | @@ -282,7 +282,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 @@ -295,7 +295,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_.md#documentdata), [DocumentData](./firestore_.md#documentdata)> The `CollectionReference` instance. @@ -310,7 +310,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 @@ -322,7 +322,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_.md#documentdata), [DocumentData](./firestore_.md#documentdata)> The created `Query`. @@ -382,7 +382,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 @@ -395,7 +395,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_.md#documentdata), [DocumentData](./firestore_.md#documentdata)> The `DocumentReference` instance. @@ -1042,15 +1042,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> | The first AggregateQuerySnapshot to compare. | +| right | [AggregateQuerySnapshot](./firestore_.aggregatequerysnapshot.md#aggregatequerysnapshot_class)<AggregateSpecType> | The second AggregateQuerySnapshot to compare. | Returns: @@ -1065,15 +1065,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)<AppType, DbType> | A Query to compare. | +| right | [Query](./firestore_.query.md#query_class)<AppType, DbType> | A Query to compare. | Returns: @@ -1088,15 +1088,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)<AppType, DbType> \| [CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<AppType, DbType> | A reference to compare. | +| right | [DocumentReference](./firestore_.documentreference.md#documentreference_class)<AppType, DbType> \| [CollectionReference](./firestore_.collectionreference.md#collectionreference_class)<AppType, DbType> | A reference to compare. | Returns: @@ -1111,15 +1111,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)<AppType, DbType> \| [QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<AppType, DbType> | A snapshot to compare. | +| right | [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<AppType, DbType> \| [QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<AppType, DbType> | A snapshot to compare. | Returns: @@ -1230,20 +1230,20 @@ The result received from the server is presented, unaltered, without considering Signature: ```typescript -export declare function getCountFromServer(query: Query): Promise(query: Query): Promise; -}>>; +}, AppType, DbType>>; ``` ### 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)<AppType, DbType> | 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>; }, AppType, DbType>> 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. @@ -1256,18 +1256,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)<AppType, DbType> | | Returns: -Promise<[QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<T>> +Promise<[QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<AppType, DbType>> A `Promise` that will be resolved with the results of the query. @@ -1278,18 +1278,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)<AppType, DbType> | | Returns: -Promise<[QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<T>> +Promise<[QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<AppType, DbType>> A `Promise` that will be resolved with the results of the query. @@ -1300,18 +1300,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)<AppType, DbType> | | Returns: -Promise<[QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<T>> +Promise<[QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<AppType, DbType>> A `Promise` that will be resolved with the results of the query. @@ -1324,8 +1324,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; @@ -1335,8 +1335,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)<AppType, DbType> | The query to listen to. | +| observer | { next?: (snapshot: [QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<AppType, DbType>) => void; error?: (error: [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class)) => void; complete?: () => void; } | A single object containing next and error callbacks. | Returns: @@ -1353,8 +1353,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; @@ -1364,9 +1364,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)<AppType, DbType> | 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)<AppType, DbType>) => void; error?: (error: [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class)) => void; complete?: () => void; } | A single object containing next and error callbacks. | Returns: @@ -1383,15 +1383,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)<AppType, DbType> | The query to listen to. | +| onNext | (snapshot: [QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<AppType, DbType>) => 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. | @@ -1410,16 +1410,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)<AppType, DbType> | 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)<AppType, DbType>) => 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. | @@ -1436,20 +1436,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)<AppType, DbType> | 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)<AppType, DbType> ## Exceptions @@ -1462,19 +1462,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)<AppType, DbType> | 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)<AppType, DbType> ## Exceptions @@ -1531,19 +1531,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)<AppType, DbType> | A reference to the collection to add this document to. | +| data | [WithFieldValue](./firestore_.md#withfieldvalue)<AppType> | 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)<AppType, DbType>> 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). @@ -1554,20 +1554,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)<AppType, DbType> | 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_.md#documentdata), [DocumentData](./firestore_.md#documentdata)> The `CollectionReference` instance. @@ -1582,20 +1582,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)<AppType, DbType> | 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_.md#documentdata), [DocumentData](./firestore_.md#documentdata)> The `CollectionReference` instance. @@ -1610,14 +1610,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)<AppType, DbType> | A reference to the document to delete. | Returns: @@ -1632,20 +1632,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)<AppType, DbType> | 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)<AppType, DbType> The `DocumentReference` instance. @@ -1660,20 +1660,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)<AppType, DbType> | 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_.md#documentdata), [DocumentData](./firestore_.md#documentdata)> The `DocumentReference` instance. @@ -1690,18 +1690,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)<AppType, DbType> | The reference of the document to fetch. | Returns: -Promise<[DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<T>> +Promise<[DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<AppType, DbType>> A Promise resolved with a `DocumentSnapshot` containing the current document contents. @@ -1712,18 +1712,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)<AppType, DbType> | | Returns: -Promise<[DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<T>> +Promise<[DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<AppType, DbType>> A `Promise` resolved with a `DocumentSnapshot` containing the current document contents. @@ -1734,18 +1734,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)<AppType, DbType> | | Returns: -Promise<[DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<T>> +Promise<[DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<AppType, DbType>> A `Promise` resolved with a `DocumentSnapshot` containing the current document contents. @@ -1758,8 +1758,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; @@ -1769,8 +1769,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)<AppType, DbType> | A reference to the document to listen to. | +| observer | { next?: (snapshot: [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<AppType, DbType>) => void; error?: (error: [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class)) => void; complete?: () => void; } | A single object containing next and error callbacks. | Returns: @@ -1787,8 +1787,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; @@ -1798,9 +1798,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)<AppType, DbType> | 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)<AppType, DbType>) => void; error?: (error: [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class)) => void; complete?: () => void; } | A single object containing next and error callbacks. | Returns: @@ -1817,15 +1817,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)<AppType, DbType> | A reference to the document to listen to. | +| onNext | (snapshot: [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<AppType, DbType>) => 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. | @@ -1844,16 +1844,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)<AppType, DbType> | 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)<AppType, DbType>) => 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. | @@ -1870,15 +1870,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)<AppType, DbType> | A reference to the document to write. | +| data | [WithFieldValue](./firestore_.md#withfieldvalue)<AppType> | A map of the fields and values for the document. | Returns: @@ -1893,15 +1893,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)<AppType, DbType> | A reference to the document to write. | +| data | [PartialWithFieldValue](./firestore_.md#partialwithfieldvalue)<AppType> | A map of the fields and values for the document. | | options | [SetOptions](./firestore_.md#setoptions) | An object to configure the set behavior. | Returns: @@ -1917,15 +1917,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)<AppType, DbType> | A reference to the document to update. | +| data | [UpdateData](./firestore_.md#updatedata)<DbType> | 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: @@ -1942,14 +1942,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)<AppType, DbType> | 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. | @@ -2200,6 +2200,16 @@ The type of a `DocumentChange` may be 'added', 'removed', or 'modified'. export declare type DocumentChangeType = 'added' | 'removed' | 'modified'; ``` +## DocumentData + +Document data (for use with [setDoc()](./firestore_lite.md#setdoc)). Must be an object with string keys. + +Signature: + +```typescript +export declare type DocumentData = Record; +``` + ## FirestoreErrorCode The set of Firestore status codes. The codes are the same at the ones exposed by gRPC here: https://github.com/grpc/grpc/blob/master/doc/statuscodes.md diff --git a/docs-devsite/firestore_.query.md b/docs-devsite/firestore_.query.md index 1961c2cc5f3..a403abfe723 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)<AppType, DbType> \| 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_.md#documentdata), [DocumentData](./firestore_.md#documentdata)> 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)<NewAppType, NewDbType> | Converts objects to and from Firestore. | Returns: -[Query](./firestore_.query.md#query_class)<U> +[Query](./firestore_.query.md#query_class)<NewAppType, NewDbType> A `Query` that uses the provided converter. diff --git a/docs-devsite/firestore_.querydocumentsnapshot.md b/docs-devsite/firestore_.querydocumentsnapshot.md index 0755a11915f..66aa1d62c91 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)<AppType, DbType> ## 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): AppType; ``` ### Parameters @@ -48,7 +48,7 @@ data(options?: SnapshotOptions): T; Returns: -T +AppType An `Object` containing all fields in the document. diff --git a/docs-devsite/firestore_.querysnapshot.md b/docs-devsite/firestore_.querysnapshot.md index 0abb869c003..cea7d0d8238 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)<AppType, DbType>> | 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)<AppType, DbType> | 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)<AppType, DbType>> ## 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)<AppType, DbType>) => 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..cefe7578996 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)<AppType, DbType> | 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)<AppType, DbType> | A reference to the document to be read. | Returns: -Promise<[DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<T>> +Promise<[DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<AppType, DbType>> 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)<AppType, DbType> | A reference to the document to be set. | +| data | [WithFieldValue](./firestore_.md#withfieldvalue)<AppType> | 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)<AppType, DbType> | A reference to the document to be set. | +| data | [PartialWithFieldValue](./firestore_.md#partialwithfieldvalue)<AppType> | 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)<AppType, DbType> | A reference to the document to be updated. | +| data | [UpdateData](./firestore_.md#updatedata)<DbType> | 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)<AppType, DbType> | 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..e8815c69641 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)<AppType, DbType> | 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)<AppType, DbType> | A reference to the document to be set. | +| data | [WithFieldValue](./firestore_.md#withfieldvalue)<AppType> | 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)<AppType, DbType> | A reference to the document to be set. | +| data | [PartialWithFieldValue](./firestore_.md#partialwithfieldvalue)<AppType> | 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)<AppType, DbType> | A reference to the document to be updated. | +| data | [UpdateData](./firestore_.md#updatedata)<DbType> | 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)<AppType, DbType> | 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..cba98d517db 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)<AppType, DbType> | 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..b0d70b85ad3 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)<AppType, DbType> ## 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.md#documentdata), [DocumentData](./firestore_lite.md#documentdata)> \| 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)<NewAppType, NewDbType> | Converts objects to and from Firestore. | Returns: -[CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<U> +[CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<NewAppType, NewDbType> 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.md#documentdata), [DocumentData](./firestore_lite.md#documentdata)> A `CollectionReference` that does not use a converter. diff --git a/docs-devsite/firestore_lite.documentdata.md b/docs-devsite/firestore_lite.documentdata.md deleted file mode 100644 index 09b5eb64b48..00000000000 --- a/docs-devsite/firestore_lite.documentdata.md +++ /dev/null @@ -1,19 +0,0 @@ -Project: /docs/reference/js/_project.yaml -Book: /docs/reference/_book.yaml -page_type: reference - -{% comment %} -DO NOT EDIT THIS FILE! -This is generated by the JS SDK team, and any local changes will be -overwritten. Changes should be made in the source code at -https://github.com/firebase/firebase-js-sdk -{% endcomment %} - -# DocumentData interface -Document data (for use with [setDoc()](./firestore_lite.md#setdoc)) consists of fields mapped to values. - -Signature: - -```typescript -export declare interface DocumentData -``` diff --git a/docs-devsite/firestore_lite.documentreference.md b/docs-devsite/firestore_lite.documentreference.md index 0e307435949..d42ccb0a827 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)<AppType, DbType> \| 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)<AppType, DbType> | 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)<NewAppType, NewDbType> | Converts objects to and from Firestore. | Returns: -[DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<U> +[DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<NewAppType, NewDbType> 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.md#documentdata), [DocumentData](./firestore_lite.md#documentdata)> 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..2eedf006fed 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)<AppType, DbType> | 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(): AppType | undefined; ``` Returns: -T \| undefined +AppType \| 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)<AppType, DbType> true if the document exists. diff --git a/docs-devsite/firestore_lite.firestoredataconverter.md b/docs-devsite/firestore_lite.firestoredataconverter.md index 00510e0c22b..0ed1cf8cc66 100644 --- a/docs-devsite/firestore_lite.firestoredataconverter.md +++ b/docs-devsite/firestore_lite.firestoredataconverter.md @@ -10,88 +10,88 @@ 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 `AppType` into Firestore data. Using the converter allows you to specify generic type arguments when storing and retrieving objects from Firestore. Signature: ```typescript -export declare interface FirestoreDataConverter +export declare interface FirestoreDataConverter ``` ## Methods | Method | Description | | --- | --- | -| [fromFirestore(snapshot)](./firestore_lite.firestoredataconverter.md#firestoredataconverterfromfirestore) | Called by the Firestore SDK to convert Firestore data into an object of type T. You can access your data by calling: snapshot.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 DbType into an object of type AppType. You can access your data by calling snapshot.data(). | +| [toFirestore(modelObject)](./firestore_lite.firestoredataconverter.md#firestoredataconvertertofirestore) | Called by the Firestore SDK to convert a custom model object of type AppType into a plain Javascript object, DbType (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 AppType into a plain Javascript object, DbType (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. | ## 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 `DbType` into an object of type `AppType`. You can access your data by calling `snapshot.data()`. Signature: ```typescript -fromFirestore(snapshot: QueryDocumentSnapshot): T; +fromFirestore(snapshot: QueryDocumentSnapshot): AppType; ``` ### 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)<DbType, DbType> | A QueryDocumentSnapshot containing your data and metadata. | Returns: -T +AppType ## 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 `AppType` into a plain Javascript object, `DbType` (suitable for writing directly to the Firestore database). 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. 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)<AppType> | | Returns: -[DocumentData](./firestore_lite.documentdata.md#documentdata_interface) +[WithFieldValue](./firestore_lite.md#withfieldvalue)<DbType> ## 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 with `merge:true` or `mergeFields`. +Called by the Firestore SDK to convert a custom model object of type `AppType` into a plain Javascript object, `DbType` (suitable for writing directly to the Firestore database). 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. 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)<AppType> | | | options | [SetOptions](./firestore_lite.md#setoptions) | | Returns: -[DocumentData](./firestore_lite.documentdata.md#documentdata_interface) +[PartialWithFieldValue](./firestore_lite.md#partialwithfieldvalue)<DbType> ### Example @@ -105,7 +105,7 @@ class Post { } } -const postConverter = { +const postConverter: FirestoreDataConverter = { toFirestore(post: WithFieldValue): DocumentData { return {title: post.title, author: post.author}; }, diff --git a/docs-devsite/firestore_lite.md b/docs-devsite/firestore_lite.md index b0ec302e722..886ad48fbd0 100644 --- a/docs-devsite/firestore_lite.md +++ b/docs-devsite/firestore_lite.md @@ -114,8 +114,7 @@ https://github.com/firebase/firebase-js-sdk | Interface | Description | | --- | --- | | [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 AppType into Firestore data.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. | @@ -127,6 +126,7 @@ https://github.com/firebase/firebase-js-sdk | [AggregateFieldType](./firestore_lite.md#aggregatefieldtype) | The union of all AggregateField types that are supported by Firestore. | | [AggregateSpecData](./firestore_lite.md#aggregatespecdata) | A type whose keys are taken from an AggregateSpec, and whose values are the result of the aggregation performed by the corresponding AggregateField from the input AggregateSpec. | | [ChildUpdateFields](./firestore_lite.md#childupdatefields) | Helper for calculating the nested fields for a given type T1. This is needed to distribute union types such as undefined | {...} (happens for optional props) or {a: A} | {b: B}.In this use case, V is used to distribute the union types of T[K] on Record, since T[K] is evaluated as an expression and not distributed.See https://www.typescriptlang.org/docs/handbook/advanced-types.html\#distributive-conditional-types | +| [DocumentData](./firestore_lite.md#documentdata) | Document data (for use with [setDoc()](./firestore_lite.md#setdoc)). Must be an object with string keys. | | [FirestoreErrorCode](./firestore_lite.md#firestoreerrorcode) | The set of Firestore status codes. The codes are the same at the ones exposed by gRPC here: https://github.com/grpc/grpc/blob/master/doc/statuscodes.mdPossible values: - 'cancelled': The operation was cancelled (typically by the caller). - 'unknown': Unknown error or an error from a different error domain. - 'invalid-argument': Client specified an invalid argument. Note that this differs from 'failed-precondition'. 'invalid-argument' indicates arguments that are problematic regardless of the state of the system (e.g. an invalid field name). - 'deadline-exceeded': Deadline expired before operation could complete. For operations that change the state of the system, this error may be returned even if the operation has completed successfully. For example, a successful response from a server could have been delayed long enough for the deadline to expire. - 'not-found': Some requested document was not found. - 'already-exists': Some document that we attempted to create already exists. - 'permission-denied': The caller does not have permission to execute the specified operation. - 'resource-exhausted': Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space. - 'failed-precondition': Operation was rejected because the system is not in a state required for the operation's execution. - 'aborted': The operation was aborted, typically due to a concurrency issue like transaction aborts, etc. - 'out-of-range': Operation was attempted past the valid range. - 'unimplemented': Operation is not implemented or not supported/enabled. - 'internal': Internal errors. Means some invariants expected by underlying system has been broken. If you see one of these errors, something is very broken. - 'unavailable': The service is currently unavailable. This is most likely a transient condition and may be corrected by retrying with a backoff. - 'data-loss': Unrecoverable data loss or corruption. - 'unauthenticated': The request does not have valid authentication credentials for the operation. | | [NestedUpdateFields](./firestore_lite.md#nestedupdatefields) | For each field (e.g. 'bar'), find all nested keys (e.g. {'bar.baz': T1, 'bar.qux': T2}). Intersect them together to make a single map containing all possible keys that are all marked as optional | | [OrderByDirection](./firestore_lite.md#orderbydirection) | The direction of a [orderBy()](./firestore_.md#orderby) clause is specified as 'desc' or 'asc' (descending or ascending). | @@ -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.md#documentdata), [DocumentData](./firestore_lite.md#documentdata)> 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.md#documentdata), [DocumentData](./firestore_lite.md#documentdata)> 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.md#documentdata), [DocumentData](./firestore_lite.md#documentdata)> 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> | The first AggregateQuerySnapshot to compare. | +| right | [AggregateQuerySnapshot](./firestore_lite.aggregatequerysnapshot.md#aggregatequerysnapshot_class)<AggregateSpecType> | 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)<AppType, DbType> | A Query to compare. | +| right | [Query](./firestore_lite.query.md#query_class)<AppType, DbType> | 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)<AppType, DbType> \| [CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<AppType, DbType> | A reference to compare. | +| right | [DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<AppType, DbType> \| [CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<AppType, DbType> | 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)<AppType, DbType> \| [QuerySnapshot](./firestore_lite.querysnapshot.md#querysnapshot_class)<AppType, DbType> | A snapshot to compare. | +| right | [DocumentSnapshot](./firestore_lite.documentsnapshot.md#documentsnapshot_class)<AppType, DbType> \| [QuerySnapshot](./firestore_lite.querysnapshot.md#querysnapshot_class)<AppType, DbType> | 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; -}>>; +}, AppType, DbType>>; ``` ### 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)<AppType, DbType> | 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>; }, AppType, DbType>> 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)<AppType, DbType> | The Query to execute. | Returns: -Promise<[QuerySnapshot](./firestore_lite.querysnapshot.md#querysnapshot_class)<T>> +Promise<[QuerySnapshot](./firestore_lite.querysnapshot.md#querysnapshot_class)<AppType, DbType>> 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)<AppType, DbType> | 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)<AppType, DbType> ## 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)<AppType, DbType> | 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)<AppType, DbType> ## 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)<AppType, DbType> | A reference to the collection to add this document to. | +| data | [WithFieldValue](./firestore_lite.md#withfieldvalue)<AppType> | 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)<AppType, DbType>> 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)<AppType, DbType> | 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.md#documentdata), [DocumentData](./firestore_lite.md#documentdata)> 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)<AppType, DbType> | 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.md#documentdata), [DocumentData](./firestore_lite.md#documentdata)> 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)<AppType, DbType> | 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)<AppType, DbType> | 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)<AppType, DbType> 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)<AppType, DbType> | 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.md#documentdata), [DocumentData](./firestore_lite.md#documentdata)> 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)<AppType, DbType> | 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)<AppType, DbType>> 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)<AppType, DbType> | A reference to the document to write. | +| data | [WithFieldValue](./firestore_lite.md#withfieldvalue)<AppType> | 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)<AppType, DbType> | A reference to the document to write. | +| data | [PartialWithFieldValue](./firestore_lite.md#partialwithfieldvalue)<AppType> | 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)<AppType, DbType> | A reference to the document to update. | +| data | [UpdateData](./firestore_lite.md#updatedata)<DbType> | 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)<AppType, DbType> | 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. | @@ -1382,6 +1382,16 @@ See https://www.typescriptlang.org/docs/handbook/advanced-types.html\#distributi export declare type ChildUpdateFields = V extends Record ? AddPrefixToKeys> : never; ``` +## DocumentData + +Document data (for use with [setDoc()](./firestore_lite.md#setdoc)). Must be an object with string keys. + +Signature: + +```typescript +export declare type DocumentData = Record; +``` + ## FirestoreErrorCode The set of Firestore status codes. The codes are the same at the ones exposed by gRPC here: https://github.com/grpc/grpc/blob/master/doc/statuscodes.md diff --git a/docs-devsite/firestore_lite.query.md b/docs-devsite/firestore_lite.query.md index f2eac7560dc..3db1ca9e91f 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)<AppType, DbType> \| 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.md#documentdata), [DocumentData](./firestore_lite.md#documentdata)> 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)<NewAppType, NewDbType> | Converts objects to and from Firestore. | Returns: -[Query](./firestore_lite.query.md#query_class)<U> +[Query](./firestore_lite.query.md#query_class)<NewAppType, NewDbType> 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..15ab55264a9 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)<AppType, DbType> ## Methods @@ -35,11 +35,11 @@ Retrieves all fields in the document as an `Object`. ```typescript /** @override */ -data(): T; +data(): AppType; ``` Returns: -T +AppType 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..d144bd133c1 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)<AppType, DbType>> | 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)<AppType, DbType> | 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)<AppType, DbType>) => 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..f730c171a42 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)<AppType, DbType> | 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)<AppType, DbType> | 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)<AppType, DbType>> 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)<AppType, DbType> | A reference to the document to be set. | +| data | [WithFieldValue](./firestore_lite.md#withfieldvalue)<AppType> | 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)<AppType, DbType> | A reference to the document to be set. | +| data | [PartialWithFieldValue](./firestore_lite.md#partialwithfieldvalue)<AppType> | 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)<AppType, DbType> | A reference to the document to be updated. | +| data | [UpdateData](./firestore_lite.md#updatedata)<DbType> | 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)<AppType, DbType> | 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..3c1896f8424 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)<AppType, DbType> | 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)<AppType, DbType> | A reference to the document to be set. | +| data | [WithFieldValue](./firestore_lite.md#withfieldvalue)<AppType> | 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)<AppType, DbType> | A reference to the document to be set. | +| data | [PartialWithFieldValue](./firestore_lite.md#partialwithfieldvalue)<AppType> | 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)<AppType, DbType> | A reference to the document to be updated. | +| data | [UpdateData](./firestore_lite.md#updatedata)<DbType> | 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)<AppType, DbType> | 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 b01cf18ee26961a41d9edc873332dbdc7d9c66bb Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Mon, 24 Apr 2023 14:28:01 -0400 Subject: [PATCH 9/9] yarn changeset --- .changeset/two-moles-sell.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/two-moles-sell.md diff --git a/.changeset/two-moles-sell.md b/.changeset/two-moles-sell.md new file mode 100644 index 00000000000..52aea728d44 --- /dev/null +++ b/.changeset/two-moles-sell.md @@ -0,0 +1,6 @@ +--- +'@firebase/firestore': major +'firebase': major +--- + +Fix typing issues with UpdateData in updateDoc(), Transaction.update(), and WriteBatch.update()