@@ -228,22 +228,25 @@ const FIRESTORE_ADDRESS = FIRESTORE_ADDRESS_ENVS.reduce(
228228) ;
229229const FIRESTORE_PORT = FIRESTORE_ADDRESS . split ( ':' ) [ 1 ] ;
230230
231- export type ClearFirestoreDataOptions = {
232- projectId : string ;
233- } ;
234-
235231/** Clears all data in firestore. Works only in offline mode.
236232 */
237- export function clearFirestoreData ( options : ClearFirestoreDataOptions ) {
233+ export function clearFirestoreData ( options : { projectId : string } | string ) {
238234 return new Promise ( ( resolve , reject ) => {
239- if ( ! options . projectId ) {
235+ let projectId ;
236+
237+ if ( typeof options === 'string' ) {
238+ projectId = options ;
239+ } else if ( typeof options === 'object' && has ( options , 'projectId' ) ) {
240+ projectId = options . projectId ;
241+ } else {
240242 throw new Error ( 'projectId not specified' ) ;
241243 }
244+
242245 const config = {
243246 method : 'DELETE' ,
244247 hostname : 'localhost' ,
245248 port : FIRESTORE_PORT ,
246- path : `/emulator/v1/projects/${ options . projectId } /databases/(default)/documents` ,
249+ path : `/emulator/v1/projects/${ projectId } /databases/(default)/documents` ,
247250 } ;
248251
249252 const req = http . request ( config , ( res ) => {
@@ -259,7 +262,7 @@ export function clearFirestoreData(options: ClearFirestoreDataOptions) {
259262 } ) ;
260263
261264 const postData = JSON . stringify ( {
262- database : `projects/${ options . projectId } /databases/(default)` ,
265+ database : `projects/${ projectId } /databases/(default)` ,
263266 } ) ;
264267
265268 req . setHeader ( 'Content-Length' , postData . length ) ;
0 commit comments