From 60970fd597110dc0785781656380f1454305081e Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Wed, 4 Nov 2020 15:50:34 -0800 Subject: [PATCH 1/2] Rename all public API types to PublicX --- packages/firestore/src/api/database.ts | 125 +++++++++++++------------ 1 file changed, 65 insertions(+), 60 deletions(-) diff --git a/packages/firestore/src/api/database.ts b/packages/firestore/src/api/database.ts index 813cad0138e..ea73df23fd1 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); } @@ -997,7 +999,7 @@ export class SnapshotMetadata implements PublicSnapshotMetadata { * True if the snapshot contains the result of local writes (for example * `set()` or `update()` calls) that have not yet been committed to the * backend. If your listener has opted into metadata updates (via - * `SnapshotListenOptions`) you will receive another snapshot with + * `PublicSnapshotListenOptions`) you will receive another snapshot with * `hasPendingWrites` equal to false once the writes have been committed to * the backend. */ @@ -1006,7 +1008,7 @@ export class SnapshotMetadata implements PublicSnapshotMetadata { /** * True if the snapshot was created from cached data rather than guaranteed * up-to-date server data. If your listener has opted into metadata updates - * (via `SnapshotListenOptions`) you will receive another snapshot with + * (via `PublicSnapshotListenOptions`) you will receive another snapshot with * `fromCache` set to false once the client has received up-to-date data from * the backend. */ @@ -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'; @@ -2110,10 +2115,10 @@ function resultChangeType(type: ChangeType): DocumentChangeType { } /** - * Converts custom model object of type T into DocumentData by applying the + * Converts custom model object of type T into PublicDocumentData by applying the * converter if it exists. * - * This function is used when converting user objects to DocumentData + * This function is used when converting user objects to PublicDocumentData * because we want to provide the user with a more specific error message if * their set() or fails due to invalid data originating from a toFirestore() * call. @@ -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; } From 424811056132ed2fdc8c7da1dd040d7ac9ccadcb Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Wed, 4 Nov 2020 15:58:46 -0800 Subject: [PATCH 2/2] Fix comments --- packages/firestore/src/api/database.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/firestore/src/api/database.ts b/packages/firestore/src/api/database.ts index ea73df23fd1..834388c17d5 100644 --- a/packages/firestore/src/api/database.ts +++ b/packages/firestore/src/api/database.ts @@ -999,7 +999,7 @@ export class SnapshotMetadata implements PublicSnapshotMetadata { * True if the snapshot contains the result of local writes (for example * `set()` or `update()` calls) that have not yet been committed to the * backend. If your listener has opted into metadata updates (via - * `PublicSnapshotListenOptions`) you will receive another snapshot with + * `SnapshotListenOptions`) you will receive another snapshot with * `hasPendingWrites` equal to false once the writes have been committed to * the backend. */ @@ -1008,7 +1008,7 @@ export class SnapshotMetadata implements PublicSnapshotMetadata { /** * True if the snapshot was created from cached data rather than guaranteed * up-to-date server data. If your listener has opted into metadata updates - * (via `PublicSnapshotListenOptions`) you will receive another snapshot with + * (via `SnapshotListenOptions`) you will receive another snapshot with * `fromCache` set to false once the client has received up-to-date data from * the backend. */ @@ -2115,10 +2115,10 @@ function resultChangeType(type: ChangeType): PublicDocumentChangeType { } /** - * Converts custom model object of type T into PublicDocumentData by applying the + * Converts custom model object of type T into DocumentData by applying the * converter if it exists. * - * This function is used when converting user objects to PublicDocumentData + * This function is used when converting user objects to DocumentData * because we want to provide the user with a more specific error message if * their set() or fails due to invalid data originating from a toFirestore() * call.