Skip to content

Commit ae79cef

Browse files
author
Shubham Bhardwaj
committed
type overloading for clearFirestoreData
1 parent e5ede41 commit ae79cef

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/providers/firestore.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,22 +228,25 @@ const FIRESTORE_ADDRESS = FIRESTORE_ADDRESS_ENVS.reduce(
228228
);
229229
const 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

Comments
 (0)