UNPKG

functional-google-cloud

Version:

Google Cloud Utilities functions in Functional Programming Style

50 lines 1.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.clearEmulator = exports.clearFirestore = exports.clearCollection = exports.getFirestore = void 0; const firestore_1 = require("@google-cloud/firestore"); /** * @internal * @type {FirebaseFirestore.Firestore} */ const firestore = new firestore_1.Firestore({ projectId: 'gcloud-project', }); /** * ```haskell * getFirestore :: () -> Firestore * ``` */ exports.getFirestore = () => firestore; /** * ```haskell * clearCollection :: Collection -> Promise * ``` */ exports.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 exports.clearCollection(collection); }); await Promise.all(deleteCollections); await document.delete(); }); await Promise.all(deleteDocuments); }; /** * ```haskell * clearFirestore :: () -> Promise * ``` */ exports.clearFirestore = async () => { const collections = await firestore.listCollections(); await Promise.all(collections.map(exports.clearCollection)); }; /** * ```haskell * clearFirebase :: () -> Promise * ``` */ exports.clearEmulator = () => Promise.resolve(); //# sourceMappingURL=Emulator.js.map