UNPKG

node-firestore-import-export

Version:
40 lines (39 loc) 1.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const admin = require("firebase-admin"); const loadJsonFile = require("load-json-file"); const getCredentialsFromFile = (credentialsFilename) => { return loadJsonFile(credentialsFilename); }; exports.getCredentialsFromFile = getCredentialsFromFile; const getFirestoreDBReference = (credentials) => { admin.initializeApp({ credential: admin.credential.cert(credentials), databaseURL: `https://${credentials.project_id}.firebaseio.com` }); return admin.firestore(); }; exports.getFirestoreDBReference = getFirestoreDBReference; const getDBReferenceFromPath = (db, dataPath) => { let startingRef; if (dataPath) { const parts = dataPath.split('/').length; const isDoc = parts % 2 === 0; startingRef = isDoc ? db.doc(dataPath) : db.collection(dataPath); } else { startingRef = db; } return startingRef; }; exports.getDBReferenceFromPath = getDBReferenceFromPath; const isLikeDocument = (ref) => { return ref.collection !== undefined; }; exports.isLikeDocument = isLikeDocument; const isRootOfDatabase = (ref) => { return ref.batch !== undefined; }; exports.isRootOfDatabase = isRootOfDatabase; const sleep = (timeInMS) => new Promise(resolve => setTimeout(resolve, timeInMS)); exports.sleep = sleep;