From 4eacbce4e5b578837a1203a3bd6e0c95b1531cb8 Mon Sep 17 00:00:00 2001 From: Brian Chen Date: Wed, 18 Dec 2019 17:55:04 -0800 Subject: [PATCH] lint --- dev/src/document-change.ts | 9 ++--- dev/src/document.ts | 29 ++++++++++++----- dev/src/index.ts | 7 ++-- dev/src/reference.ts | 67 ++++++++++++++++++++++++++------------ dev/src/types.ts | 2 +- dev/src/watch.ts | 43 +++++++++++++++--------- dev/src/write-batch.ts | 4 ++- 7 files changed, 108 insertions(+), 53 deletions(-) diff --git a/dev/src/document-change.ts b/dev/src/document-change.ts index 134c1bcd2..bdb73a0fc 100644 --- a/dev/src/document-change.ts +++ b/dev/src/document-change.ts @@ -14,10 +14,10 @@ * limitations under the License. */ -import { FirestoreDataConverter } from '@google-cloud/firestore'; +import {FirestoreDataConverter} from '@google-cloud/firestore'; import {QueryDocumentSnapshot} from './document'; -import { DocumentData } from './types'; -import { defaultConverter } from './watch'; +import {DocumentData} from './types'; +import {defaultConverter} from './watch'; export type DocumentChangeType = 'added' | 'removed' | 'modified'; @@ -55,7 +55,8 @@ export class DocumentChange { this._document = document; this._oldIndex = oldIndex; this._newIndex = newIndex; - this._converter = converter || defaultConverter as FirestoreDataConverter; + this._converter = + converter || (defaultConverter as FirestoreDataConverter); } /** diff --git a/dev/src/document.ts b/dev/src/document.ts index 0ba491f27..f70b9ed6f 100644 --- a/dev/src/document.ts +++ b/dev/src/document.ts @@ -28,8 +28,8 @@ import {ApiMapValue, DocumentData, UpdateMap} from './types'; import {isEmpty, isObject} from './util'; import api = google.firestore.v1; -import { FirestoreDataConverter } from '@google-cloud/firestore'; -import { defaultConverter } from './watch'; +import {FirestoreDataConverter} from '@google-cloud/firestore'; +import {defaultConverter} from './watch'; /** * Returns a builder for DocumentSnapshot and QueryDocumentSnapshot instances. @@ -56,7 +56,8 @@ export class DocumentSnapshotBuilder { private readonly _converter: FirestoreDataConverter; constructor(converter?: FirestoreDataConverter) { - this._converter = converter || defaultConverter as FirestoreDataConverter; + this._converter = + converter || (defaultConverter as FirestoreDataConverter); } /** @@ -84,7 +85,14 @@ export class DocumentSnapshotBuilder { this.updateTime!, this.ref!._converter ) - : new DocumentSnapshot(this.ref!, undefined, this.readTime!, undefined, undefined, this.ref!._converter); + : new DocumentSnapshot( + this.ref!, + undefined, + this.readTime!, + undefined, + undefined, + this.ref!._converter + ); } } @@ -109,7 +117,7 @@ export class DocumentSnapshot { private _readTime: Timestamp | undefined; private _createTime: Timestamp | undefined; private _updateTime: Timestamp | undefined; - private readonly _converter: FirestoreDataConverter; + private readonly _converter: FirestoreDataConverter; /** * @hideconstructor @@ -138,8 +146,9 @@ export class DocumentSnapshot { this._readTime = readTime; this._createTime = createTime; this._updateTime = updateTime; - this._converter = converter || defaultConverter as FirestoreDataConverter; - } + this._converter = + converter || (defaultConverter as FirestoreDataConverter); + } /** * Creates a DocumentSnapshot from an object. @@ -507,7 +516,7 @@ export class DocumentSnapshot { (other instanceof DocumentSnapshot && this._ref.isEqual(other._ref) && deepEqual(this._fieldsProto, other._fieldsProto, {strict: true}) && - this._converter === other._converter) + this._converter === other._converter) ); } } @@ -527,7 +536,9 @@ export class DocumentSnapshot { * @class * @extends DocumentSnapshot */ -export class QueryDocumentSnapshot extends DocumentSnapshot { +export class QueryDocumentSnapshot extends DocumentSnapshot< + T +> { /** * @hideconstructor * diff --git a/dev/src/index.ts b/dev/src/index.ts index 795f248f2..fa038b546 100644 --- a/dev/src/index.ts +++ b/dev/src/index.ts @@ -60,7 +60,7 @@ import { import {WriteBatch} from './write-batch'; import api = google.firestore.v1; -import { DocumentData } from '@google-cloud/firestore'; +import {DocumentData} from '@google-cloud/firestore'; export { CollectionReference, @@ -954,7 +954,10 @@ export class Firestore { 'Received document: %s', response.found.name! ); - document = self.snapshot_(response.found, response.readTime!); + document = self.snapshot_( + response.found, + response.readTime! + ); } else { logger( 'Firestore.getAll_', diff --git a/dev/src/reference.ts b/dev/src/reference.ts index 6fd296f92..6d800f9ac 100644 --- a/dev/src/reference.ts +++ b/dev/src/reference.ts @@ -59,7 +59,7 @@ import {defaultConverter, DocumentWatch, QueryWatch} from './watch'; import {validateDocumentData, WriteBatch, WriteResult} from './write-batch'; import api = proto.google.firestore.v1; -import { FirestoreDataConverter } from '@google-cloud/firestore'; +import {FirestoreDataConverter} from '@google-cloud/firestore'; /** * The direction of a `Query.orderBy()` clause is specified as 'desc' or 'asc' @@ -125,7 +125,7 @@ const comparisonOperators: { */ export class DocumentReference implements Serializable { readonly _converter: FirestoreDataConverter; - + /** * @hideconstructor * @@ -137,7 +137,8 @@ export class DocumentReference implements Serializable { readonly _path: ResourcePath, converter?: FirestoreDataConverter ) { - this._converter = converter || defaultConverter as FirestoreDataConverter; + this._converter = + converter || (defaultConverter as FirestoreDataConverter); } /** @@ -224,7 +225,11 @@ export class DocumentReference implements Serializable { * }): */ get parent(): CollectionReference { - return new CollectionReference(this._firestore, this._path.parent()!, this._converter); + return new CollectionReference( + this._firestore, + this._path.parent()!, + this._converter + ); } /** @@ -439,7 +444,11 @@ export class DocumentReference implements Serializable { const writeBatch = new WriteBatch(this._firestore); return writeBatch.update - .apply(writeBatch, [this as DocumentReference, dataOrField, ...preconditionOrValues]) + .apply(writeBatch, [ + this as DocumentReference, + dataOrField, + ...preconditionOrValues, + ]) .commit() .then(([writeResult]) => writeResult); } @@ -489,7 +498,11 @@ export class DocumentReference implements Serializable { // The document is missing. const document = new DocumentSnapshotBuilder(); - document.ref = new DocumentReference(this._firestore, this._path, this._converter); + document.ref = new DocumentReference( + this._firestore, + this._path, + this._converter + ); document.readTime = readTime; onNext(document.build()); }, onError || console.error); @@ -530,9 +543,7 @@ export class DocumentReference implements Serializable { * @param converter Converts objects to and from Firestore. * @return A DocumentReference that uses the provided converter. */ - withConverter( - converter: FirestoreDataConverter - ): DocumentReference { + withConverter(converter: FirestoreDataConverter): DocumentReference { return new DocumentReference(this.firestore, this._path, converter); } } @@ -689,7 +700,8 @@ export class QuerySnapshot { ) { this._docs = docs; this._changes = changes; - this._converter = converter || defaultConverter as FirestoreDataConverter; + this._converter = + converter || (defaultConverter as FirestoreDataConverter); } /** @@ -1042,7 +1054,8 @@ export class Query { converter?: FirestoreDataConverter ) { this._serializer = new Serializer(_firestore); - this._converter = converter || defaultConverter as FirestoreDataConverter; + this._converter = + converter || (defaultConverter as FirestoreDataConverter); } /** @@ -1475,7 +1488,11 @@ export class Query { ); } - reference = new DocumentReference(this._firestore, basePath.append(val), this._converter); + reference = new DocumentReference( + this._firestore, + basePath.append(val), + this._converter + ); } else if (val instanceof DocumentReference) { reference = val; if (!basePath.isPrefixOf(reference._path)) { @@ -1707,7 +1724,9 @@ export class Query { () => { const changes: Array> = []; for (let i = 0; i < docs.length; ++i) { - changes.push(new DocumentChange('added', docs[i], -1, i, this._converter)); + changes.push( + new DocumentChange('added', docs[i], -1, i, this._converter) + ); } return changes; }, @@ -1979,9 +1998,7 @@ export class Query { * @param converter Converts objects to and from Firestore. * @return A Query that uses the provided converter. */ - withConverter( - converter: FirestoreDataConverter - ): Query { + withConverter(converter: FirestoreDataConverter): Query { return new Query(this.firestore, this._queryOptions, converter); } } @@ -1994,14 +2011,18 @@ export class Query { * @class * @extends Query */ -export class CollectionReference extends Query { +export class CollectionReference extends Query { /** * @hideconstructor * * @param firestore The Firestore Database client. * @param path The Path of this collection. */ - constructor(firestore: Firestore, path: ResourcePath, _converter?: FirestoreDataConverter) { + constructor( + firestore: Firestore, + path: ResourcePath, + _converter?: FirestoreDataConverter + ) { super(firestore, QueryOptions.forCollectionQuery(path), _converter); } @@ -2209,7 +2230,11 @@ export class CollectionReference extends Query { withConverter( converter: FirestoreDataConverter ): CollectionReference { - return new CollectionReference(this.firestore, this.resourcePath, converter); + return new CollectionReference( + this.firestore, + this.resourcePath, + converter + ); } } @@ -2236,8 +2261,8 @@ export function validateQueryOrder( export function defaultDataConverter(): FirestoreDataConverter { return { toFirestore: data => data, - fromFirestore: data => data as DocumentData - } + fromFirestore: data => data as DocumentData, + }; } /** diff --git a/dev/src/types.ts b/dev/src/types.ts index 02706dfc8..52cd8787d 100644 --- a/dev/src/types.ts +++ b/dev/src/types.ts @@ -81,7 +81,7 @@ export interface Settings { * mapped to values. */ export interface DocumentData { - // tslint:disable-next-line:no-any + // tslint:disable-next-line:no-any [field: string]: any; } diff --git a/dev/src/watch.ts b/dev/src/watch.ts index c1f6b770f..407600c67 100644 --- a/dev/src/watch.ts +++ b/dev/src/watch.ts @@ -29,17 +29,21 @@ import {DocumentData, GrpcError, RBTree} from './types'; import {requestTag} from './util'; import api = google.firestore.v1; -import { FirestoreDataConverter } from '@google-cloud/firestore'; +import {FirestoreDataConverter} from '@google-cloud/firestore'; export const defaultConverter = { - toFirestore(modelObject: FirebaseFirestore.DocumentData): FirebaseFirestore.DocumentData { - return modelObject; - }, - fromFirestore(data: FirebaseFirestore.DocumentData):FirebaseFirestore.DocumentData { - return data; - } - }; - + toFirestore( + modelObject: FirebaseFirestore.DocumentData + ): FirebaseFirestore.DocumentData { + return modelObject; + }, + fromFirestore( + data: FirebaseFirestore.DocumentData + ): FirebaseFirestore.DocumentData { + return data; + }, +}; + /*! * Target ID used by watch. Watch uses a fixed target id since we only support * one target per stream. @@ -319,7 +323,8 @@ abstract class Watch { this.requestTag = requestTag(); this.onNext = EMPTY_FUNCTION; this.onError = EMPTY_FUNCTION; - this._converter = converter || defaultConverter as FirestoreDataConverter; + this._converter = + converter || (defaultConverter as FirestoreDataConverter); } /** Returns a 'Target' proto denoting the target to listen on. */ @@ -754,7 +759,9 @@ abstract class Watch { * Returns the DocumentChange event for successful modifications. * @private */ - private modifyDoc(newDocument: QueryDocumentSnapshot): DocumentChange | null { + private modifyDoc( + newDocument: QueryDocumentSnapshot + ): DocumentChange | null { const name = newDocument.ref.path; assert(this.docMap.has(name), 'Document to modify does not exist'); const oldDocument = this.docMap.get(name)!; @@ -873,8 +880,11 @@ abstract class Watch { * @private */ export class DocumentWatch extends Watch { - constructor(firestore: Firestore, private readonly ref: DocumentReference, - converter?: FirestoreDataConverter) { + constructor( + firestore: Firestore, + private readonly ref: DocumentReference, + converter?: FirestoreDataConverter + ) { super(firestore, converter); } @@ -902,8 +912,11 @@ export class DocumentWatch extends Watch { export class QueryWatch extends Watch { private comparator: DocumentComparator; - constructor(firestore: Firestore, private readonly query: Query, - converter?: FirestoreDataConverter) { + constructor( + firestore: Firestore, + private readonly query: Query, + converter?: FirestoreDataConverter + ) { super(firestore, converter); this.comparator = query.comparator(); } diff --git a/dev/src/write-batch.ts b/dev/src/write-batch.ts index b02fe40e0..cf53a44f5 100644 --- a/dev/src/write-batch.ts +++ b/dev/src/write-batch.ts @@ -185,7 +185,9 @@ export class WriteBatch { this.verifyNotCommitted(); - const firestoreData = documentRef._converter ? documentRef._converter.toFirestore(data) : data as T; + const firestoreData = documentRef._converter + ? documentRef._converter.toFirestore(data) + : (data as T); const transform = DocumentTransform.fromObject(documentRef, firestoreData); transform.validate();