Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Chen committed May 25, 2021
1 parent bd96583 commit ea8782a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 23 deletions.
31 changes: 21 additions & 10 deletions dev/src/index.ts
Expand Up @@ -79,7 +79,7 @@ import {CollectionGroup} from './collection-group';
import {
RECURSIVE_DELETE_MAX_PENDING_OPS,
RECURSIVE_DELETE_MIN_PENDING_OPS,
RecursiveDelete
RecursiveDelete,
} from './recursive-delete';

export {
Expand Down Expand Up @@ -1255,7 +1255,12 @@ export class Firestore implements firestore.Firestore {
| firestore.DocumentReference<unknown>,
bulkWriter?: BulkWriter
): Promise<void> {
return this._recursiveDelete(ref, RECURSIVE_DELETE_MAX_PENDING_OPS, RECURSIVE_DELETE_MIN_PENDING_OPS, bulkWriter);
return this._recursiveDelete(
ref,
RECURSIVE_DELETE_MAX_PENDING_OPS,
RECURSIVE_DELETE_MIN_PENDING_OPS,
bulkWriter
);
}

/**
Expand All @@ -1266,15 +1271,21 @@ export class Firestore implements firestore.Firestore {
*/
// Visible for testing
_recursiveDelete(
ref:
| firestore.CollectionReference<unknown>
| firestore.DocumentReference<unknown>,
maxPendingOps: number,
minPendingOps: number,
bulkWriter?: BulkWriter
): Promise<void> {
ref:
| firestore.CollectionReference<unknown>
| firestore.DocumentReference<unknown>,
maxPendingOps: number,
minPendingOps: number,
bulkWriter?: BulkWriter
): Promise<void> {
const writer = bulkWriter ?? this.getBulkWriter();
const deleter = new RecursiveDelete(this, writer, ref, maxPendingOps, minPendingOps);
const deleter = new RecursiveDelete(
this,
writer,
ref,
maxPendingOps,
minPendingOps
);
return deleter.run();
}

Expand Down
13 changes: 6 additions & 7 deletions dev/src/recursive-delete.ts
Expand Up @@ -134,6 +134,9 @@ export class RecursiveDelete {
* @param firestore The Firestore instance to use.
* @param writer The BulkWriter instance to use for delete operations.
* @param ref The document or collection reference to recursively delete.
* @param maxLimit The query limit to use when fetching descendants
* @param minLimit The number of pending BulkWriter operations at which
* RecursiveDelete starts the next limit query to fetch descendants.
*/
constructor(
private readonly firestore: Firestore,
Expand All @@ -142,7 +145,7 @@ export class RecursiveDelete {
| firestore.CollectionReference<unknown>
| firestore.DocumentReference<unknown>,
private readonly maxLimit: number,
private readonly minLimit: number,
private readonly minLimit: number
) {
this.maxPendingOps = maxLimit;
this.minPendingOps = minLimit;
Expand All @@ -154,10 +157,7 @@ export class RecursiveDelete {
* if an error occurs.
*/
run(): Promise<void> {
assert(
!this.started,
'RecursiveDelete.run() should only be called once.'
);
assert(!this.started, 'RecursiveDelete.run() should only be called once.');

// Capture the error stack to preserve stack tracing across async calls.
this.errorStack = Error().stack!;
Expand All @@ -175,7 +175,7 @@ export class RecursiveDelete {
const stream = this.getAllDescendants(
this.ref instanceof CollectionReference
? (this.ref as CollectionReference<unknown>)
: (this.ref as DocumentReference<unknown>),
: (this.ref as DocumentReference<unknown>)
);
this.streamInProgress = true;
let streamedDocsCount = 0;
Expand Down Expand Up @@ -206,7 +206,6 @@ export class RecursiveDelete {
/**
* Retrieves all descendant documents nested under the provided reference.
* @param ref The reference to fetch all descendants for.
* @param limit The number of descendants to fetch in the query.
* @private
* @return {Stream<QueryDocumentSnapshot>} Stream of descendant documents.
*/
Expand Down
20 changes: 14 additions & 6 deletions dev/test/recursive-delete.ts
Expand Up @@ -50,8 +50,11 @@ import {
import {MAX_REQUEST_RETRIES} from '../src';

import api = google.firestore.v1;
import {RECURSIVE_DELETE_MAX_PENDING_OPS, REFERENCE_NAME_MIN_ID} from '../src/recursive-delete';
import {Deferred} from "../src/util";
import {
RECURSIVE_DELETE_MAX_PENDING_OPS,
REFERENCE_NAME_MIN_ID,
} from '../src/recursive-delete';
import {Deferred} from '../src/util';

const PROJECT_ID = 'test-project';
const DATABASE_ROOT = `projects/${PROJECT_ID}/databases/(default)`;
Expand Down Expand Up @@ -254,12 +257,12 @@ describe('recursiveDelete() method:', () => {
// This deferred completes when the second query is run.
const secondQueryDeferred = new Deferred<void>();

const firstStream = Array.from(Array(maxPendingOps).keys()).map(
(_, i) => result('doc' + i)
const firstStream = Array.from(Array(maxPendingOps).keys()).map((_, i) =>
result('doc' + i)
);

const batchWriteResponse = mergeResponses(
Array.from(Array(maxBatchSize).keys()).map(() => successResponse(1))
Array.from(Array(maxBatchSize).keys()).map(() => successResponse(1))
);

// Use an array to store that the queryEquals() method succeeded, since
Expand Down Expand Up @@ -342,7 +345,12 @@ describe('recursiveDelete() method:', () => {

const bulkWriter = firestore.bulkWriter();
bulkWriter._maxBatchSize = maxBatchSize;
await firestore._recursiveDelete(firestore.collection('root'), maxPendingOps, minPendingOps, bulkWriter);
await firestore._recursiveDelete(
firestore.collection('root'),
maxPendingOps,
minPendingOps,
bulkWriter
);
expect(called).to.deep.equal([1, 2]);
});
});
Expand Down

0 comments on commit ea8782a

Please sign in to comment.