UNPKG

functional-google-cloud

Version:

Google Cloud Utilities functions in Functional Programming Style

47 lines 1.3 kB
import { Firestore } from '@google-cloud/firestore'; /** * @internal * @type {FirebaseFirestore.Firestore} */ const firestore = new Firestore({ projectId: 'gcloud-project', }); /** * ```haskell * getFirestore :: () -> Firestore * ``` */ export const getFirestore = () => firestore; /** * ```haskell * clearCollection :: Collection -> Promise * ``` */ export const clearCollection = async (parentCollection) => { const documents = await parentCollection.listDocuments(); const deleteDocuments = documents.map(async (document) => { const collections = await document.listCollections(); const deleteCollections = collections.map(async (collection) => { await clearCollection(collection); }); await Promise.all(deleteCollections); await document.delete(); }); await Promise.all(deleteDocuments); }; /** * ```haskell * clearFirestore :: () -> Promise * ``` */ export const clearFirestore = async () => { const collections = await firestore.listCollections(); await Promise.all(collections.map(clearCollection)); }; /** * ```haskell * clearFirebase :: () -> Promise * ``` */ export const clearEmulator = () => Promise.resolve(); //# sourceMappingURL=Emulator.js.map