diff --git a/packages/firestore/src/api/database.ts b/packages/firestore/src/api/database.ts index 813cad0138e..834388c17d5 100644 --- a/packages/firestore/src/api/database.ts +++ b/packages/firestore/src/api/database.ts @@ -115,27 +115,27 @@ import { Compat } from '../compat/compat'; import { CollectionReference as PublicCollectionReference, DocumentChange as PublicDocumentChange, - DocumentChangeType, - DocumentData, + DocumentChangeType as PublicDocumentChangeType, + DocumentData as PublicDocumentData, DocumentReference as PublicDocumentReference, DocumentSnapshot as PublicDocumentSnapshot, FirebaseFirestore as PublicFirestore, - FirestoreDataConverter, - GetOptions, + FirestoreDataConverter as PublicFirestoreDataConverter, + GetOptions as PublicGetOptions, LogLevel as PublicLogLevel, - OrderByDirection, + OrderByDirection as PublicOrderByDirection, PersistenceSettings as PublicPersistenceSettings, Query as PublicQuery, QueryDocumentSnapshot as PublicQueryDocumentSnapshot, QuerySnapshot as PublicQuerySnapshot, - SetOptions, + SetOptions as PublicSetOptions, Settings as PublicSettings, - SnapshotListenOptions, + SnapshotListenOptions as PublicSnapshotListenOptions, SnapshotMetadata as PublicSnapshotMetadata, SnapshotOptions as PublicSnapshotOptions, Transaction as PublicTransaction, - UpdateData, - WhereFilterOp, + UpdateData as PublicUpdateData, + WhereFilterOp as PublicWhereFilterOp, WriteBatch as PublicWriteBatch } from '@firebase/firestore-types'; import { newUserDataReader } from '../../lite/src/api/reference'; @@ -481,13 +481,13 @@ export class Transaction implements PublicTransaction { set( documentRef: DocumentReference, data: Partial, - options: SetOptions + options: PublicSetOptions ): Transaction; set(documentRef: DocumentReference, data: T): Transaction; set( documentRef: PublicDocumentReference, value: T | Partial, - options?: SetOptions + options?: PublicSetOptions ): Transaction { const ref = validateReference( 'Transaction.set', @@ -514,7 +514,7 @@ export class Transaction implements PublicTransaction { update( documentRef: PublicDocumentReference, - value: UpdateData + value: PublicUpdateData ): Transaction; update( documentRef: PublicDocumentReference, @@ -524,7 +524,7 @@ export class Transaction implements PublicTransaction { ): Transaction; update( documentRef: PublicDocumentReference, - fieldOrUpdateData: string | ExternalFieldPath | UpdateData, + fieldOrUpdateData: string | ExternalFieldPath | PublicUpdateData, value?: unknown, ...moreFieldsAndValues: unknown[] ): Transaction { @@ -589,13 +589,13 @@ export class WriteBatch implements PublicWriteBatch { set( documentRef: DocumentReference, data: Partial, - options: SetOptions + options: PublicSetOptions ): WriteBatch; set(documentRef: DocumentReference, data: T): WriteBatch; set( documentRef: PublicDocumentReference, value: T | Partial, - options?: SetOptions + options?: PublicSetOptions ): WriteBatch { this.verifyNotCommitted(); const ref = validateReference( @@ -625,7 +625,7 @@ export class WriteBatch implements PublicWriteBatch { update( documentRef: PublicDocumentReference, - value: UpdateData + value: PublicUpdateData ): WriteBatch; update( documentRef: PublicDocumentReference, @@ -635,7 +635,7 @@ export class WriteBatch implements PublicWriteBatch { ): WriteBatch; update( documentRef: PublicDocumentReference, - fieldOrUpdateData: string | ExternalFieldPath | UpdateData, + fieldOrUpdateData: string | ExternalFieldPath | PublicUpdateData, value?: unknown, ...moreFieldsAndValues: unknown[] ): WriteBatch { @@ -719,7 +719,7 @@ export class WriteBatch implements PublicWriteBatch { /** * A reference to a particular document in a collection in the database. */ -export class DocumentReference +export class DocumentReference extends _DocumentKeyReference implements PublicDocumentReference { private _firestoreClient: FirestoreClient; @@ -728,7 +728,7 @@ export class DocumentReference constructor( public _key: DocumentKey, readonly firestore: Firestore, - readonly _converter: FirestoreDataConverter | null + readonly _converter: PublicFirestoreDataConverter | null ) { super(firestore._databaseId, _key, _converter); this._firestoreClient = ensureFirestoreConfigured(firestore._delegate); @@ -738,7 +738,7 @@ export class DocumentReference static forPath( path: ResourcePath, firestore: Firestore, - converter: FirestoreDataConverter | null + converter: PublicFirestoreDataConverter | null ): DocumentReference { if (path.length % 2 !== 0) { throw new FirestoreError( @@ -767,7 +767,9 @@ export class DocumentReference return this._key.path.canonicalString(); } - collection(pathString: string): PublicCollectionReference { + collection( + pathString: string + ): PublicCollectionReference { validateNonEmptyArgument( 'DocumentReference.collection', 'path', @@ -798,9 +800,9 @@ export class DocumentReference ); } - set(value: Partial, options: SetOptions): Promise; + set(value: Partial, options: PublicSetOptions): Promise; set(value: T): Promise; - set(value: T | Partial, options?: SetOptions): Promise { + set(value: T | Partial, options?: PublicSetOptions): Promise { options = validateSetOptions('DocumentReference.set', options); const convertedValue = applyFirestoreDataConverter( this._converter, @@ -821,14 +823,14 @@ export class DocumentReference ); } - update(value: UpdateData): Promise; + update(value: PublicUpdateData): Promise; update( field: string | ExternalFieldPath, value: unknown, ...moreFieldsAndValues: unknown[] ): Promise; update( - fieldOrUpdateData: string | ExternalFieldPath | UpdateData, + fieldOrUpdateData: string | ExternalFieldPath | PublicUpdateData, value?: unknown, ...moreFieldsAndValues: unknown[] ): Promise { @@ -875,7 +877,7 @@ export class DocumentReference onSnapshot(observer: PartialObserver>): Unsubscribe; onSnapshot( - options: SnapshotListenOptions, + options: PublicSnapshotListenOptions, observer: PartialObserver> ): Unsubscribe; onSnapshot( @@ -884,7 +886,7 @@ export class DocumentReference onCompletion?: CompleteFn ): Unsubscribe; onSnapshot( - options: SnapshotListenOptions, + options: PublicSnapshotListenOptions, onNext: NextFn>, onError?: ErrorFn, onCompletion?: CompleteFn @@ -899,7 +901,7 @@ export class DocumentReference typeof args[currArg] === 'object' && !isPartialObserver(args[currArg]) ) { - options = args[currArg] as SnapshotListenOptions; + options = args[currArg] as PublicSnapshotListenOptions; currArg++; } @@ -936,7 +938,7 @@ export class DocumentReference ); } - get(options?: GetOptions): Promise> { + get(options?: PublicGetOptions): Promise> { if (options && options.source === 'cache') { return firestoreClientGetDocumentFromLocalCache( this._firestoreClient, @@ -962,7 +964,7 @@ export class DocumentReference } withConverter( - converter: FirestoreDataConverter + converter: PublicFirestoreDataConverter ): PublicDocumentReference { return new DocumentReference(this._key, this.firestore, converter); } @@ -1037,7 +1039,7 @@ export class SnapshotMetadata implements PublicSnapshotMetadata { */ export interface SnapshotOptions extends PublicSnapshotOptions {} -export class DocumentSnapshot +export class DocumentSnapshot implements PublicDocumentSnapshot { constructor( private _firestore: Firestore, @@ -1045,7 +1047,7 @@ export class DocumentSnapshot public _document: Document | null, private _fromCache: boolean, private _hasPendingWrites: boolean, - private readonly _converter: FirestoreDataConverter | null + private readonly _converter: PublicFirestoreDataConverter | null ) {} data(options: PublicSnapshotOptions = {}): T | undefined { @@ -1136,7 +1138,7 @@ export class DocumentSnapshot } } -export class QueryDocumentSnapshot +export class QueryDocumentSnapshot extends DocumentSnapshot implements PublicQueryDocumentSnapshot { data(options?: SnapshotOptions): T { @@ -1542,20 +1544,20 @@ export function validateHasExplicitOrderByForLimitToLast( } } -export class Query implements PublicQuery { +export class Query implements PublicQuery { private _dataReader: UserDataReader; constructor( public _query: InternalQuery, readonly firestore: Firestore, - protected readonly _converter: FirestoreDataConverter | null + protected readonly _converter: PublicFirestoreDataConverter | null ) { this._dataReader = newUserDataReader(firestore._delegate); } where( field: string | ExternalFieldPath, - opStr: WhereFilterOp, + opStr: PublicWhereFilterOp, value: unknown ): PublicQuery { const fieldPath = fieldPathFromArgument('Query.where', field); @@ -1577,7 +1579,7 @@ export class Query implements PublicQuery { orderBy( field: string | ExternalFieldPath, - directionStr?: OrderByDirection + directionStr?: PublicOrderByDirection ): PublicQuery { let direction: Direction; if (directionStr === undefined || directionStr === 'asc') { @@ -1697,7 +1699,7 @@ export class Query implements PublicQuery { ); } - withConverter(converter: FirestoreDataConverter): PublicQuery { + withConverter(converter: PublicFirestoreDataConverter): PublicQuery { return new Query(this._query, this.firestore, converter); } @@ -1731,7 +1733,7 @@ export class Query implements PublicQuery { onSnapshot(observer: PartialObserver>): Unsubscribe; onSnapshot( - options: SnapshotListenOptions, + options: PublicSnapshotListenOptions, observer: PartialObserver> ): Unsubscribe; onSnapshot( @@ -1740,7 +1742,7 @@ export class Query implements PublicQuery { onCompletion?: CompleteFn ): Unsubscribe; onSnapshot( - options: SnapshotListenOptions, + options: PublicSnapshotListenOptions, onNext: NextFn>, onError?: ErrorFn, onCompletion?: CompleteFn @@ -1753,7 +1755,7 @@ export class Query implements PublicQuery { typeof args[currArg] === 'object' && !isPartialObserver(args[currArg]) ) { - options = args[currArg] as SnapshotListenOptions; + options = args[currArg] as PublicSnapshotListenOptions; currArg++; } @@ -1789,7 +1791,7 @@ export class Query implements PublicQuery { return firestoreClientListen(client, this._query, options, observer); } - get(options?: GetOptions): Promise> { + get(options?: PublicGetOptions): Promise> { validateHasExplicitOrderByForLimitToLast(this._query); const client = ensureFirestoreConfigured(this.firestore._delegate); @@ -1807,7 +1809,8 @@ export class Query implements PublicQuery { } } -export class QuerySnapshot implements PublicQuerySnapshot { +export class QuerySnapshot + implements PublicQuerySnapshot { private _cachedChanges: Array> | null = null; private _cachedChangesIncludeMetadataChanges: boolean | null = null; @@ -1817,7 +1820,7 @@ export class QuerySnapshot implements PublicQuerySnapshot { private readonly _firestore: Firestore, private readonly _originalQuery: InternalQuery, private readonly _snapshot: ViewSnapshot, - private readonly _converter: FirestoreDataConverter | null + private readonly _converter: PublicFirestoreDataConverter | null ) { this.metadata = new SnapshotMetadata( _snapshot.hasPendingWrites, @@ -1859,7 +1862,9 @@ export class QuerySnapshot implements PublicQuerySnapshot { return new Query(this._originalQuery, this._firestore, this._converter); } - docChanges(options?: SnapshotListenOptions): Array> { + docChanges( + options?: PublicSnapshotListenOptions + ): Array> { if (options) { } @@ -1920,13 +1925,13 @@ export class QuerySnapshot implements PublicQuerySnapshot { } } -export class CollectionReference +export class CollectionReference extends Query implements PublicCollectionReference { constructor( readonly _path: ResourcePath, firestore: Firestore, - _converter: FirestoreDataConverter | null + _converter: PublicFirestoreDataConverter | null ) { super(newQueryForPath(_path), firestore, _converter); if (_path.length % 2 !== 1) { @@ -1943,12 +1948,12 @@ export class CollectionReference return this._query.path.lastSegment(); } - get parent(): PublicDocumentReference | null { + get parent(): PublicDocumentReference | null { const parentPath = this._query.path.popLast(); if (parentPath.isEmpty()) { return null; } else { - return new DocumentReference( + return new DocumentReference( new DocumentKey(parentPath), this.firestore, /* converter= */ null @@ -1992,7 +1997,7 @@ export class CollectionReference } withConverter( - converter: FirestoreDataConverter + converter: PublicFirestoreDataConverter ): PublicCollectionReference { return new CollectionReference(this._path, this.firestore, converter); } @@ -2033,7 +2038,7 @@ export function changesFromSnapshot( hasPendingWrite: boolean ) => DocSnap ): Array<{ - type: DocumentChangeType; + type: PublicDocumentChangeType; doc: DocSnap; oldIndex: number; newIndex: number; @@ -2059,7 +2064,7 @@ export function changesFromSnapshot( ); lastDoc = change.doc; return { - type: 'added' as DocumentChangeType, + type: 'added' as PublicDocumentChangeType, doc, oldIndex: -1, newIndex: index++ @@ -2095,7 +2100,7 @@ export function changesFromSnapshot( } } -function resultChangeType(type: ChangeType): DocumentChangeType { +function resultChangeType(type: ChangeType): PublicDocumentChangeType { switch (type) { case ChangeType.Added: return 'added'; @@ -2121,8 +2126,8 @@ function resultChangeType(type: ChangeType): DocumentChangeType { export function applyFirestoreDataConverter( converter: UntypedFirestoreDataConverter | null, value: T, - options?: SetOptions -): DocumentData { + options?: PublicSetOptions +): PublicDocumentData { let convertedValue; if (converter) { if (options && (options.merge || options.mergeFields)) { @@ -2134,7 +2139,7 @@ export function applyFirestoreDataConverter( convertedValue = converter.toFirestore(value); } } else { - convertedValue = value as DocumentData; + convertedValue = value as PublicDocumentData; } return convertedValue; }