Socket
Socket
Sign inDemoInstall

firestore-export-import

Package Overview
Dependencies
3
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.3 to 1.3.4

16

dist/export.js

@@ -1,2 +0,2 @@

var __assign=(this&&this.__assign)||function(){__assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i<n;i++){s=arguments[i];for(var p in s)if(Object.prototype.hasOwnProperty.call(s,p))
"use strict";var __assign=(this&&this.__assign)||function(){__assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i<n;i++){s=arguments[i];for(var p in s)if(Object.prototype.hasOwnProperty.call(s,p))
t[p]=s[p];}

@@ -15,10 +15,10 @@ return t;};return __assign.apply(this,arguments);};var __awaiter=(this&&this.__awaiter)||function(thisArg,_arguments,P,generator){function adopt(value){return value instanceof P?value:new P(function(resolve){resolve(value);});}

if(op[0]&5)throw op[1];return{value:op[0]?op[1]:void 0,done:true};}};var __spreadArray=(this&&this.__spreadArray)||function(to,from,pack){if(pack||arguments.length===2)for(var i=0,l=from.length,ar;i<l;i++){if(ar||!(i in from)){if(!ar)ar=Array.prototype.slice.call(from,0,i);ar[i]=from[i];}}
return to.concat(ar||Array.prototype.slice.call(from));};import{getFirestore}from'firebase-admin/firestore';import{getPath,traverseObjects}from'./helper.js';export var getAllCollectionsService=function(collectionNameArray,options){return __awaiter(void 0,void 0,void 0,function(){var db,paths,snap,promises,value;return __generator(this,function(_a){switch(_a.label){case 0:db=getFirestore();paths=collectionNameArray;if(!(paths.length===0))return[3,2];return[4,db.listCollections()];case 1:snap=_a.sent();snap.forEach(function(collection){return paths.push(collection.path);});_a.label=2;case 2:promises=paths.map(function(path){return backupService(path,options);});return[4,Promise.all(promises)];case 3:value=_a.sent();return[2,Object.assign.apply(Object,__spreadArray([{}],value,false))];}});});};export var backupFromDocService=function(collectionName,documentName,options){return __awaiter(void 0,void 0,void 0,function(){var db,data,documentRef,document,docs,_i,docs_1,doc,subCollections,_a,_b,refKey,_c,_d,val,_e,subCollections_1,subCol,subColData,error_1;return __generator(this,function(_f){switch(_f.label){case 0:_f.trys.push([0,9,,10]);db=getFirestore();data={};data[collectionName]={};documentRef=db.collection(collectionName).doc(documentName);return[4,documentRef.get()];case 1:document=_f.sent();docs=[document];_i=0,docs_1=docs;_f.label=2;case 2:if(!(_i<docs_1.length))return[3,8];doc=docs_1[_i];return[4,doc.ref.listCollections()];case 3:subCollections=_f.sent();data[collectionName][doc.id]=doc.data()||{};if(options===null||options===void 0?void 0:options.refs){for(_a=0,_b=options===null||options===void 0?void 0:options.refs;_a<_b.length;_a++){refKey=_b[_a];if(refKey.indexOf('.')>-1){traverseObjects(data,function(value){var _a;if(((_a=value.constructor)===null||_a===void 0?void 0:_a.name)!=='DocumentReference'){return null;}
return getPath(value);});}
else{if(data[collectionName][doc.id][refKey]){if(Array.isArray(data[collectionName][doc.id][refKey])){for(_c=0,_d=data[collectionName][doc.id][refKey];_c<_d.length;_c++){val=_d[_c];data[collectionName][doc.id][refKey]=getPath(val);}}
return to.concat(ar||Array.prototype.slice.call(from));};Object.defineProperty(exports,"__esModule",{value:true});exports.backupService=exports.backUpDocRef=exports.backupFromDocService=exports.getAllCollectionsService=void 0;var firestore_1=require("firebase-admin/firestore");var helper_js_1=require("./helper.js");var getAllCollectionsService=function(collectionNameArray,options){return __awaiter(void 0,void 0,void 0,function(){var db,paths,snap,promises,value;return __generator(this,function(_a){switch(_a.label){case 0:db=(0,firestore_1.getFirestore)();paths=collectionNameArray;if(!(paths.length===0))return[3,2];return[4,db.listCollections()];case 1:snap=_a.sent();snap.forEach(function(collection){return paths.push(collection.path);});_a.label=2;case 2:promises=paths.map(function(path){return(0,exports.backupService)(path,options);});return[4,Promise.all(promises)];case 3:value=_a.sent();return[2,Object.assign.apply(Object,__spreadArray([{}],value,false))];}});});};exports.getAllCollectionsService=getAllCollectionsService;var backupFromDocService=function(collectionName,documentName,options){return __awaiter(void 0,void 0,void 0,function(){var db,data,documentRef,document,docs,_i,docs_1,doc,subCollections,_a,_b,refKey,_c,_d,val,_e,subCollections_1,subCol,subColData,error_1;return __generator(this,function(_f){switch(_f.label){case 0:_f.trys.push([0,9,,10]);db=(0,firestore_1.getFirestore)();data={};data[collectionName]={};documentRef=db.collection(collectionName).doc(documentName);return[4,documentRef.get()];case 1:document=_f.sent();docs=[document];_i=0,docs_1=docs;_f.label=2;case 2:if(!(_i<docs_1.length))return[3,8];doc=docs_1[_i];return[4,doc.ref.listCollections()];case 3:subCollections=_f.sent();data[collectionName][doc.id]=doc.data()||{};if(options===null||options===void 0?void 0:options.refs){for(_a=0,_b=options===null||options===void 0?void 0:options.refs;_a<_b.length;_a++){refKey=_b[_a];if(refKey.indexOf('.')>-1){(0,helper_js_1.traverseObjects)(data,function(value){var _a;if(((_a=value.constructor)===null||_a===void 0?void 0:_a.name)!=='DocumentReference'){return null;}
return(0,helper_js_1.getPath)(value);});}
else{if(data[collectionName][doc.id][refKey]){if(Array.isArray(data[collectionName][doc.id][refKey])){for(_c=0,_d=data[collectionName][doc.id][refKey];_c<_d.length;_c++){val=_d[_c];data[collectionName][doc.id][refKey]=(0,helper_js_1.getPath)(val);}}
else if(typeof data[collectionName][doc.id][refKey].path==='string'){data[collectionName][doc.id][refKey]=data[collectionName][doc.id][refKey].path;}}}}}
if(!(subCollections.length>0))return[3,7];data[collectionName][doc.id]['subCollection']={};_e=0,subCollections_1=subCollections;_f.label=4;case 4:if(!(_e<subCollections_1.length))return[3,7];subCol=subCollections_1[_e];return[4,backupService("".concat(collectionName,"/").concat(documentName,"/").concat(subCol.id),options)];case 5:subColData=_f.sent();data[collectionName][doc.id]['subCollection']=__assign(__assign({},data[collectionName][doc.id]['subCollection']),subColData);_f.label=6;case 6:_e++;return[3,4];case 7:_i++;return[3,2];case 8:return[2,data];case 9:error_1=_f.sent();console.error(error_1);throw new Error(error_1);case 10:return[2];}});});};export var backUpDocRef=function(doc,collectionPath,options){return __awaiter(void 0,void 0,void 0,function(){var subCollections,data,_i,_a,refKey,_b,_c,val,_d,subCollections_2,subCol,subColData,tR;return __generator(this,function(_e){switch(_e.label){case 0:return[4,doc.ref.listCollections()];case 1:subCollections=_e.sent();data=Object.assign({},doc.data());if(options===null||options===void 0?void 0:options.refs){for(_i=0,_a=options===null||options===void 0?void 0:options.refs;_i<_a.length;_i++){refKey=_a[_i];if(refKey.indexOf('.')>-1){traverseObjects(data,function(value){var _a;if(((_a=value.constructor)===null||_a===void 0?void 0:_a.name)!=='DocumentReference'){return null;}
return getPath(value);});}
else{if(data[refKey]){if(Array.isArray(data[refKey])){for(_b=0,_c=data[refKey];_b<_c.length;_b++){val=_c[_b];data[refKey]=getPath(val);}}
if(!(subCollections.length>0))return[3,7];data[collectionName][doc.id]['subCollection']={};_e=0,subCollections_1=subCollections;_f.label=4;case 4:if(!(_e<subCollections_1.length))return[3,7];subCol=subCollections_1[_e];return[4,(0,exports.backupService)("".concat(collectionName,"/").concat(documentName,"/").concat(subCol.id),options)];case 5:subColData=_f.sent();data[collectionName][doc.id]['subCollection']=__assign(__assign({},data[collectionName][doc.id]['subCollection']),subColData);_f.label=6;case 6:_e++;return[3,4];case 7:_i++;return[3,2];case 8:return[2,data];case 9:error_1=_f.sent();console.error(error_1);throw new Error(error_1);case 10:return[2];}});});};exports.backupFromDocService=backupFromDocService;var backUpDocRef=function(doc,collectionPath,options){return __awaiter(void 0,void 0,void 0,function(){var subCollections,data,_i,_a,refKey,_b,_c,val,_d,subCollections_2,subCol,subColData,tR;return __generator(this,function(_e){switch(_e.label){case 0:return[4,doc.ref.listCollections()];case 1:subCollections=_e.sent();data=Object.assign({},doc.data());if(options===null||options===void 0?void 0:options.refs){for(_i=0,_a=options===null||options===void 0?void 0:options.refs;_i<_a.length;_i++){refKey=_a[_i];if(refKey.indexOf('.')>-1){(0,helper_js_1.traverseObjects)(data,function(value){var _a;if(((_a=value.constructor)===null||_a===void 0?void 0:_a.name)!=='DocumentReference'){return null;}
return(0,helper_js_1.getPath)(value);});}
else{if(data[refKey]){if(Array.isArray(data[refKey])){for(_b=0,_c=data[refKey];_b<_c.length;_b++){val=_c[_b];data[refKey]=(0,helper_js_1.getPath)(val);}}
else if(typeof data[refKey].path==='string'){data[refKey]=data[refKey].path;}}}}}
if(!(subCollections.length>0))return[3,5];data['subCollection']={};_d=0,subCollections_2=subCollections;_e.label=2;case 2:if(!(_d<subCollections_2.length))return[3,5];subCol=subCollections_2[_d];return[4,backupService("".concat(collectionPath,"/").concat(doc.id,"/").concat(subCol.id),options)];case 3:subColData=_e.sent();data['subCollection']=__assign(__assign({},data['subCollection']),subColData);_e.label=4;case 4:_d++;return[3,2];case 5:tR={};tR[doc.id]=data;return[2,tR];}});});};export var backupService=function(collectionName,options){return __awaiter(void 0,void 0,void 0,function(){var db,data_1,collectionRef_1,documents,_a,docs,promises,promiseValues,error_2;return __generator(this,function(_b){switch(_b.label){case 0:_b.trys.push([0,6,,7]);db=getFirestore();data_1={};data_1[collectionName]={};collectionRef_1=db.collection(collectionName);if(!((options===null||options===void 0?void 0:options.queryCollection)!=null))return[3,2];return[4,options.queryCollection(collectionRef_1)];case 1:_a=_b.sent();return[3,4];case 2:return[4,collectionRef_1.get()];case 3:_a=_b.sent();_b.label=4;case 4:documents=_a;docs=(options===null||options===void 0?void 0:options.docsFromEachCollection)>0?documents.docs.slice(0,options===null||options===void 0?void 0:options.docsFromEachCollection):documents.docs;promises=docs.map(function(doc){return backUpDocRef(doc,collectionRef_1.path,options);});return[4,Promise.all(promises)];case 5:promiseValues=_b.sent();promiseValues.forEach(function(dataMap){data_1[collectionName]=Object.assign(data_1[collectionName],dataMap);});return[2,data_1];case 6:error_2=_b.sent();console.error(error_2);throw new Error(error_2);case 7:return[2];}});});};
if(!(subCollections.length>0))return[3,5];data['subCollection']={};_d=0,subCollections_2=subCollections;_e.label=2;case 2:if(!(_d<subCollections_2.length))return[3,5];subCol=subCollections_2[_d];return[4,(0,exports.backupService)("".concat(collectionPath,"/").concat(doc.id,"/").concat(subCol.id),options)];case 3:subColData=_e.sent();data['subCollection']=__assign(__assign({},data['subCollection']),subColData);_e.label=4;case 4:_d++;return[3,2];case 5:tR={};tR[doc.id]=data;return[2,tR];}});});};exports.backUpDocRef=backUpDocRef;var backupService=function(collectionName,options){return __awaiter(void 0,void 0,void 0,function(){var db,data_1,collectionRef_1,documents,_a,docs,promises,promiseValues,error_2;return __generator(this,function(_b){switch(_b.label){case 0:_b.trys.push([0,6,,7]);db=(0,firestore_1.getFirestore)();data_1={};data_1[collectionName]={};collectionRef_1=db.collection(collectionName);if(!((options===null||options===void 0?void 0:options.queryCollection)!=null))return[3,2];return[4,options.queryCollection(collectionRef_1)];case 1:_a=_b.sent();return[3,4];case 2:return[4,collectionRef_1.get()];case 3:_a=_b.sent();_b.label=4;case 4:documents=_a;docs=(options===null||options===void 0?void 0:options.docsFromEachCollection)>0?documents.docs.slice(0,options===null||options===void 0?void 0:options.docsFromEachCollection):documents.docs;promises=docs.map(function(doc){return(0,exports.backUpDocRef)(doc,collectionRef_1.path,options);});return[4,Promise.all(promises)];case 5:promiseValues=_b.sent();promiseValues.forEach(function(dataMap){data_1[collectionName]=Object.assign(data_1[collectionName],dataMap);});return[2,data_1];case 6:error_2=_b.sent();console.error(error_2);throw new Error(error_2);case 7:return[2];}});});};exports.backupService=backupService;

@@ -1,8 +0,9 @@

import{GeoPoint}from"firebase-admin/firestore";export var makeGeoPoint=function(geoValues){if(!geoValues._latitude||!geoValues._longitude){return null;}
return new GeoPoint(geoValues._latitude,geoValues._longitude);};export var makeTime=function(firebaseTimestamp){if(!firebaseTimestamp||!firebaseTimestamp._seconds){return null;}
return new Date(firebaseTimestamp._seconds*1000);};export var getPath=function(obj){if(obj&&typeof obj.path==='string'){return obj.path;}
return obj;};var isObject=function(test){return(test===null||test===void 0?void 0:test.constructor)===Object;};var isArray=function(test){return Array.isArray(test);};export var traverseObjects=function(data,callback){var _a;for(var _i=0,_b=Object.entries(data);_i<_b.length;_i++){var _c=_b[_i],key=_c[0],value=_c[1];if(!isObject(value)&&!isArray(value)&&((_a=value===null||value===void 0?void 0:value.constructor)===null||_a===void 0?void 0:_a.name)!=='DocumentReference'){continue;}
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.parseAndConvertGeos=exports.parseAndConvertDates=exports.traverseObjects=exports.getPath=exports.makeTime=exports.makeGeoPoint=void 0;var firestore_1=require("firebase-admin/firestore");var makeGeoPoint=function(geoValues){if(!geoValues._latitude||!geoValues._longitude){return null;}
return new firestore_1.GeoPoint(geoValues._latitude,geoValues._longitude);};exports.makeGeoPoint=makeGeoPoint;var makeTime=function(firebaseTimestamp){if(!firebaseTimestamp||!firebaseTimestamp._seconds){return null;}
return new Date(firebaseTimestamp._seconds*1000);};exports.makeTime=makeTime;var getPath=function(obj){if(obj&&typeof obj.path==='string'){return obj.path;}
return obj;};exports.getPath=getPath;var isObject=function(test){return(test===null||test===void 0?void 0:test.constructor)===Object;};var isArray=function(test){return Array.isArray(test);};var traverseObjects=function(data,callback){var _a;for(var _i=0,_b=Object.entries(data);_i<_b.length;_i++){var _c=_b[_i],key=_c[0],value=_c[1];if(!isObject(value)&&!isArray(value)&&((_a=value===null||value===void 0?void 0:value.constructor)===null||_a===void 0?void 0:_a.name)!=='DocumentReference'){continue;}
var checkResult=callback(value);if(checkResult){data[key]=checkResult;continue;}
traverseObjects(data[key],callback);}};export var parseAndConvertDates=function(data){traverseObjects(data,function(value){var isTimeStamp=typeof value==='object'&&value.hasOwnProperty('_seconds')&&value.hasOwnProperty('_nanoseconds');if(isTimeStamp){return makeTime(value);}
return null;});};export function parseAndConvertGeos(data){traverseObjects(data,function(value){var isGeoPoint=typeof value==="object"&&value.hasOwnProperty("_latitude")&&value.hasOwnProperty("_longitude");if(isGeoPoint){return makeGeoPoint(value);}
return null;});}
(0,exports.traverseObjects)(data[key],callback);}};exports.traverseObjects=traverseObjects;var parseAndConvertDates=function(data){(0,exports.traverseObjects)(data,function(value){var isTimeStamp=typeof value==='object'&&value.hasOwnProperty('_seconds')&&value.hasOwnProperty('_nanoseconds');if(isTimeStamp){return(0,exports.makeTime)(value);}
return null;});};exports.parseAndConvertDates=parseAndConvertDates;function parseAndConvertGeos(data){(0,exports.traverseObjects)(data,function(value){var isGeoPoint=typeof value==="object"&&value.hasOwnProperty("_latitude")&&value.hasOwnProperty("_longitude");if(isGeoPoint){return(0,exports.makeGeoPoint)(value);}
return null;});}
exports.parseAndConvertGeos=parseAndConvertGeos;

@@ -1,2 +0,2 @@

var __awaiter=(this&&this.__awaiter)||function(thisArg,_arguments,P,generator){function adopt(value){return value instanceof P?value:new P(function(resolve){resolve(value);});}
"use strict";var __awaiter=(this&&this.__awaiter)||function(thisArg,_arguments,P,generator){function adopt(value){return value instanceof P?value:new P(function(resolve){resolve(value);});}
return new(P||(P=Promise))(function(resolve,reject){function fulfilled(value){try{step(generator.next(value));}catch(e){reject(e);}}

@@ -12,13 +12,13 @@ function rejected(value){try{step(generator["throw"](value));}catch(e){reject(e);}}

op=body.call(thisArg,_);}catch(e){op=[6,e];y=0;}finally{f=t=0;}
if(op[0]&5)throw op[1];return{value:op[0]?op[1]:void 0,done:true};}};import{getFirestore}from'firebase-admin/firestore';import fs from'fs';import{v1 as uuidv1}from'uuid';import{makeTime,traverseObjects,parseAndConvertDates,makeGeoPoint,parseAndConvertGeos,}from'./helper.js';export var restoreService=function(fileName,options){var db=getFirestore();return new Promise(function(resolve,reject){if(typeof fileName==='object'){var dataObj=fileName;updateCollection(db,dataObj,options).then(function(){resolve({status:true,message:'Collection successfully imported!',});}).catch(function(error){reject({status:false,message:error.message});});}
else{fs.readFile(fileName,'utf8',function(err,data){if(err){console.log(err);reject({status:false,message:err.message});}
var dataObj=JSON.parse(data);updateCollection(db,dataObj,options).then(function(){resolve({status:true,message:'Collection successfully imported!',});}).catch(function(error){reject({status:false,message:error.message});});});}});};var updateCollection=function(db,dataObj,options){if(options===void 0){options={};}
if(op[0]&5)throw op[1];return{value:op[0]?op[1]:void 0,done:true};}};var __importDefault=(this&&this.__importDefault)||function(mod){return(mod&&mod.__esModule)?mod:{"default":mod};};Object.defineProperty(exports,"__esModule",{value:true});exports.restoreService=void 0;var firestore_1=require("firebase-admin/firestore");var fs_1=__importDefault(require("fs"));var uuid_1=require("uuid");var helper_js_1=require("./helper.js");var restoreService=function(fileName,options){var db=(0,firestore_1.getFirestore)();return new Promise(function(resolve,reject){if(typeof fileName==='object'){var dataObj=fileName;updateCollection(db,dataObj,options).then(function(){resolve({status:true,message:'Collection successfully imported!',});}).catch(function(error){reject({status:false,message:error.message});});}
else{fs_1.default.readFile(fileName,'utf8',function(err,data){if(err){console.log(err);reject({status:false,message:err.message});}
var dataObj=JSON.parse(data);updateCollection(db,dataObj,options).then(function(){resolve({status:true,message:'Collection successfully imported!',});}).catch(function(error){reject({status:false,message:error.message});});});}});};exports.restoreService=restoreService;var updateCollection=function(db,dataObj,options){if(options===void 0){options={};}
return __awaiter(void 0,void 0,void 0,function(){var _a,_b,_i,index,collectionName,_c,_d,_e,doc,docId,subCollections,error_1,subCollections,_f,_g,_h,subIndex,revivedSubCollection,subCollectionPath;return __generator(this,function(_j){switch(_j.label){case 0:_a=[];for(_b in dataObj)
_a.push(_b);_i=0;_j.label=1;case 1:if(!(_i<_a.length))return[3,16];index=_a[_i];collectionName=index;_c=[];for(_d in dataObj[index])
_c.push(_d);_e=0;_j.label=2;case 2:if(!(_e<_c.length))return[3,15];doc=_c[_e];if(!dataObj[index].hasOwnProperty(doc))return[3,14];docId=Array.isArray(dataObj[index])?uuidv1():doc;if(!!Array.isArray(dataObj[index]))return[3,9];subCollections=dataObj[index][docId]['subCollection'];delete dataObj[index][doc]['subCollection'];_j.label=3;case 3:_j.trys.push([3,5,,6]);return[4,startUpdating(db,collectionName,docId,dataObj[index][doc],options)];case 4:_j.sent();return[3,6];case 5:error_1=_j.sent();console.error(error_1);return[3,6];case 6:if(!subCollections)return[3,8];return[4,updateCollection(db,subCollections,options)];case 7:_j.sent();_j.label=8;case 8:return[3,14];case 9:subCollections=dataObj[index][doc]['subCollection'];delete dataObj[index][doc]['subCollection'];return[4,startUpdating(db,collectionName,docId,dataObj[index][doc],options)];case 10:_j.sent();if(!subCollections)return[3,14];_f=[];for(_g in subCollections)
_f.push(_g);_h=0;_j.label=11;case 11:if(!(_h<_f.length))return[3,14];subIndex=_f[_h];revivedSubCollection={};subCollectionPath="".concat(collectionName,"/").concat(docId,"/").concat(subIndex);revivedSubCollection[subCollectionPath]=subCollections[subIndex];return[4,updateCollection(db,revivedSubCollection,options)];case 12:_j.sent();_j.label=13;case 13:_h++;return[3,11];case 14:_e++;return[3,2];case 15:_i++;return[3,1];case 16:return[2];}});});};var startUpdating=function(db,collectionName,docId,data,options){var _a;if(options.dates&&options.dates.length>0){options.dates.forEach(function(date){if(data.hasOwnProperty(date)){if(Array.isArray(data[date])){data[date]=data[date].map(function(d){return makeTime(d);});}
else{data[date]=makeTime(data[date]);}}
if(date.indexOf('.')>-1){traverseObjects(data,function(value){if(!value.hasOwnProperty('_seconds')){return null;}
return makeTime(value);});}});}
if(options.autoParseDates){parseAndConvertDates(data);}
_c.push(_d);_e=0;_j.label=2;case 2:if(!(_e<_c.length))return[3,15];doc=_c[_e];if(!dataObj[index].hasOwnProperty(doc))return[3,14];docId=Array.isArray(dataObj[index])?(0,uuid_1.v1)():doc;if(!!Array.isArray(dataObj[index]))return[3,9];subCollections=dataObj[index][docId]['subCollection'];delete dataObj[index][doc]['subCollection'];_j.label=3;case 3:_j.trys.push([3,5,,6]);return[4,startUpdating(db,collectionName,docId,dataObj[index][doc],options)];case 4:_j.sent();return[3,6];case 5:error_1=_j.sent();console.error(error_1);return[3,6];case 6:if(!subCollections)return[3,8];return[4,updateCollection(db,subCollections,options)];case 7:_j.sent();_j.label=8;case 8:return[3,14];case 9:subCollections=dataObj[index][doc]['subCollection'];delete dataObj[index][doc]['subCollection'];return[4,startUpdating(db,collectionName,docId,dataObj[index][doc],options)];case 10:_j.sent();if(!subCollections)return[3,14];_f=[];for(_g in subCollections)
_f.push(_g);_h=0;_j.label=11;case 11:if(!(_h<_f.length))return[3,14];subIndex=_f[_h];revivedSubCollection={};subCollectionPath="".concat(collectionName,"/").concat(docId,"/").concat(subIndex);revivedSubCollection[subCollectionPath]=subCollections[subIndex];return[4,updateCollection(db,revivedSubCollection,options)];case 12:_j.sent();_j.label=13;case 13:_h++;return[3,11];case 14:_e++;return[3,2];case 15:_i++;return[3,1];case 16:return[2];}});});};var startUpdating=function(db,collectionName,docId,data,options){var _a;if(options.dates&&options.dates.length>0){options.dates.forEach(function(date){if(data.hasOwnProperty(date)){if(Array.isArray(data[date])){data[date]=data[date].map(function(d){return(0,helper_js_1.makeTime)(d);});}
else{data[date]=(0,helper_js_1.makeTime)(data[date]);}}
if(date.indexOf('.')>-1){(0,helper_js_1.traverseObjects)(data,function(value){if(!value.hasOwnProperty('_seconds')){return null;}
return(0,helper_js_1.makeTime)(value);});}});}
if(options.autoParseDates){(0,helper_js_1.parseAndConvertDates)(data);}
if((_a=options.refs)===null||_a===void 0?void 0:_a.length){options.refs.forEach(function(ref){if(data.hasOwnProperty(ref)){if(Array.isArray(data[ref])){data[ref]=data[ref].map(function(dataRef){return db.doc(dataRef);});}

@@ -32,7 +32,7 @@ else{data[ref]=db.doc(data[ref]);}}

else{return(prev[curr]=prev[curr]||null);}}},data);}});}
if(options.geos&&options.geos.length>0){options.geos.forEach(function(geo){if(data.hasOwnProperty(geo)){if(Array.isArray(data[geo])){data[geo]=data[geo].map(function(geoValues){return makeGeoPoint(geoValues);});}
else{data[geo]=makeGeoPoint(data[geo]);}}
if(geo.indexOf('.')>-1){traverseObjects(data,function(value){if(!value.hasOwnProperty('_latitude')){return null;}
return makeGeoPoint(value);});}});}
if(options.autoParseGeos){parseAndConvertGeos(data);}
if(options.geos&&options.geos.length>0){options.geos.forEach(function(geo){if(data.hasOwnProperty(geo)){if(Array.isArray(data[geo])){data[geo]=data[geo].map(function(geoValues){return(0,helper_js_1.makeGeoPoint)(geoValues);});}
else{data[geo]=(0,helper_js_1.makeGeoPoint)(data[geo]);}}
if(geo.indexOf('.')>-1){(0,helper_js_1.traverseObjects)(data,function(value){if(!value.hasOwnProperty('_latitude')){return null;}
return(0,helper_js_1.makeGeoPoint)(value);});}});}
if(options.autoParseGeos){(0,helper_js_1.parseAndConvertGeos)(data);}
return new Promise(function(resolve,reject){db.collection(collectionName).doc(docId).set(data).then(function(){(options===null||options===void 0?void 0:options.showLogs)&&console.log("".concat(docId," was successfully added to firestore!"));resolve({status:true,message:"".concat(docId," was successfully added to firestore!"),});}).catch(function(error){console.log(error);reject({status:false,message:error.message,});});});};

@@ -1,8 +0,8 @@

var __assign=(this&&this.__assign)||function(){__assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i<n;i++){s=arguments[i];for(var p in s)if(Object.prototype.hasOwnProperty.call(s,p))
"use strict";var __assign=(this&&this.__assign)||function(){__assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i<n;i++){s=arguments[i];for(var p in s)if(Object.prototype.hasOwnProperty.call(s,p))
t[p]=s[p];}
return t;};return __assign.apply(this,arguments);};import{cert,getApps,initializeApp}from'firebase-admin/app';import{getFirestore}from'firebase-admin/firestore';import{backupFromDocService,getAllCollectionsService,backupService}from'./export.js';import{restoreService}from'./import.js';export var initializeFirebaseApp=function(serviceAccount,name,options){if(name===void 0){name='[DEFAULT]';}
return t;};return __assign.apply(this,arguments);};Object.defineProperty(exports,"__esModule",{value:true});exports.backups=exports.restore=exports.backupFromDoc=exports.backup=exports.initializeFirebaseApp=void 0;var app_1=require("firebase-admin/app");var firestore_1=require("firebase-admin/firestore");var export_js_1=require("./export.js");var import_js_1=require("./import.js");var initializeFirebaseApp=function(serviceAccount,name,options){if(name===void 0){name='[DEFAULT]';}
if(options===void 0){options={};}
var apps=getApps();if(apps.length===0||(apps.length>0&&apps[0].name!==name)){initializeApp({credential:cert(serviceAccount),databaseURL:serviceAccount['databaseURL'],},name);getFirestore().settings(__assign({timestampsInSnapshots:true},options.firestore));}
return true;};export var backup=function(collectionName,options){return backupService(collectionName,options);};export var backupFromDoc=function(collectionName,documentName,options){return backupFromDocService(collectionName,documentName,options);};export var restore=function(fileName,options){if(options===void 0){options={};}
return restoreService(fileName,options);};export var backups=function(collectionNameArray,options){if(collectionNameArray===void 0){collectionNameArray=[];}
return getAllCollectionsService(collectionNameArray,options);};
var apps=(0,app_1.getApps)();if(apps.length===0||(apps.length>0&&apps[0].name!==name)){(0,app_1.initializeApp)({credential:(0,app_1.cert)(serviceAccount),databaseURL:serviceAccount['databaseURL'],},name);(0,firestore_1.getFirestore)().settings(__assign({timestampsInSnapshots:true},options.firestore));}
return true;};exports.initializeFirebaseApp=initializeFirebaseApp;var backup=function(collectionName,options){return(0,export_js_1.backupService)(collectionName,options);};exports.backup=backup;var backupFromDoc=function(collectionName,documentName,options){return(0,export_js_1.backupFromDocService)(collectionName,documentName,options);};exports.backupFromDoc=backupFromDoc;var restore=function(fileName,options){if(options===void 0){options={};}
return(0,import_js_1.restoreService)(fileName,options);};exports.restore=restore;var backups=function(collectionNameArray,options){if(collectionNameArray===void 0){collectionNameArray=[];}
return(0,export_js_1.getAllCollectionsService)(collectionNameArray,options);};exports.backups=backups;
{
"name": "firestore-export-import",
"version": "1.3.3",
"version": "1.3.4",
"description": "NPM package for backup and restore Firebase Firestore",
"exports": "./dist/index.js",
"main": "./dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"files": [

@@ -9,0 +8,0 @@ "readme.md",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc