import { Firestore , Query , QueryDocumentSnapshot , QuerySnapshot , WriteBatch } from '../client/firebase-admin' ; /**
 * From https://firebase.google.com/docs/firestore/manage-data/delete-data
 */ export function deleteCollection ( db , collectionPath , batchSize ) { const query = db . collection ( collectionPath ) . limit ( batchSize ) ; return new Promise ( ( resolve , reject ) => { deleteQueryBatch ( db , query , batchSize , resolve , reject ) ; } ) ; } function deleteQueryBatch ( db , query , batchSize , resolve , reject ) { query . get ( ) . then ( ( snapshot ) => { if ( snapshot . size === 0 ) { return snapshot . size ; } const batch = db . batch ( ) ; snapshot . docs . forEach ( ( doc ) => batch . delete ( doc . ref ) ) ; return batch . commit ( ) . then ( ( ) => snapshot . size ) ; } ) . then ( ( numDeleted ) => { if ( numDeleted === 0 ) { resolve ( ) ; return ; } process . nextTick ( ( ) => deleteQueryBatch ( db , query , batchSize , resolve , reject ) ) ; } ) . catch ( reject ) ; }