Socket
Socket
Sign inDemoInstall

firestore-export-import

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

firestore-export-import - npm Package Compare versions

Comparing version 0.2.6 to 0.2.7

6

dist/import.js

@@ -11,7 +11,7 @@ "use strict";var __awaiter=(this&&this.__awaiter)||function(thisArg,_arguments,P,generator){return new(P||(P=Promise))(function(resolve,reject){function fulfilled(value){try{step(generator.next(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};}};var __importStar=(this&&this.__importStar)||function(mod){if(mod&&mod.__esModule)return mod;var result={};if(mod!=null)for(var k in mod)if(Object.hasOwnProperty.call(mod,k))result[k]=mod[k];result["default"]=mod;return result;};var _this=this;Object.defineProperty(exports,"__esModule",{value:true});var admin=__importStar(require("firebase-admin"));var fs=__importStar(require("fs"));exports.restore=function(fileName,dateArray,geoArray){var db=admin.firestore();return new Promise(function(resolve,reject){if(typeof fileName==='object'){var dataArray=fileName;udpateCollection(db,dataArray,dateArray,geoArray).then(function(){resolve({status:true,message:'Successfully import collection!'});}).catch(function(error){reject({status:false,message:error.message});});}
if(op[0]&5)throw op[1];return{value:op[0]?op[1]:void 0,done:true};}};var __importStar=(this&&this.__importStar)||function(mod){if(mod&&mod.__esModule)return mod;var result={};if(mod!=null)for(var k in mod)if(Object.hasOwnProperty.call(mod,k))result[k]=mod[k];result["default"]=mod;return result;};var _this=this;Object.defineProperty(exports,"__esModule",{value:true});var admin=__importStar(require("firebase-admin"));var fs=__importStar(require("fs"));exports.restore=function(fileName,dateArray,geoArray){var db=admin.firestore();return new Promise(function(resolve,reject){if(typeof fileName==='object'){var dataArray=fileName;updateCollection(db,dataArray,dateArray,geoArray).then(function(){resolve({status:true,message:'Successfully import collection!'});}).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 dataArray=JSON.parse(data);udpateCollection(db,dataArray,dateArray,geoArray).then(function(){resolve({status:true,message:'Successfully import collection!'});}).catch(function(error){reject({status:false,message:error.message});});});}});};var udpateCollection=function(db,dataArray,dateArray,geoArray){return __awaiter(_this,void 0,void 0,function(){var _a,_b,_i,index,collectionName,_c,_d,_e,doc,subCollections;return __generator(this,function(_f){switch(_f.label){case 0:_a=[];for(_b in dataArray)
var dataArray=JSON.parse(data);updateCollection(db,dataArray,dateArray,geoArray).then(function(){resolve({status:true,message:'Successfully import collection!'});}).catch(function(error){reject({status:false,message:error.message});});});}});};var updateCollection=function(db,dataArray,dateArray,geoArray){return __awaiter(_this,void 0,void 0,function(){var _a,_b,_i,index,collectionName,_c,_d,_e,doc,subCollections;return __generator(this,function(_f){switch(_f.label){case 0:_a=[];for(_b in dataArray)
_a.push(_b);_i=0;_f.label=1;case 1:if(!(_i<_a.length))return[3,9];index=_a[_i];collectionName=index;_c=[];for(_d in dataArray[index])
_c.push(_d);_e=0;_f.label=2;case 2:if(!(_e<_c.length))return[3,8];doc=_c[_e];if(!dataArray[index].hasOwnProperty(doc))return[3,7];if(!dataArray[index][doc]['subCollection'])return[3,5];subCollections=dataArray[index][doc]['subCollection'];delete dataArray[index][doc]['subCollection'];return[4,startUpdating(db,collectionName,doc,dataArray[index][doc],dateArray,geoArray)];case 3:_f.sent();return[4,udpateCollection(db,subCollections,[],[])];case 4:_f.sent();return[3,7];case 5:return[4,startUpdating(db,collectionName,doc,dataArray[index][doc],dateArray,geoArray)];case 6:_f.sent();_f.label=7;case 7:_e++;return[3,2];case 8:_i++;return[3,1];case 9:return[2];}});});};var startUpdating=function(db,collectionName,doc,data,dateArray,geoArray){var parameterValid=true;if(typeof dateArray==='object'&&dateArray.length>0){dateArray.map(function(date){if(data.hasOwnProperty(date)){data[date]=new Date(data[date]._seconds*1000);}
_c.push(_d);_e=0;_f.label=2;case 2:if(!(_e<_c.length))return[3,8];doc=_c[_e];if(!dataArray[index].hasOwnProperty(doc))return[3,7];if(!dataArray[index][doc]['subCollection'])return[3,5];subCollections=dataArray[index][doc]['subCollection'];delete dataArray[index][doc]['subCollection'];return[4,startUpdating(db,collectionName,doc,dataArray[index][doc],dateArray,geoArray)];case 3:_f.sent();return[4,updateCollection(db,subCollections,[],[])];case 4:_f.sent();return[3,7];case 5:return[4,startUpdating(db,collectionName,doc,dataArray[index][doc],dateArray,geoArray)];case 6:_f.sent();_f.label=7;case 7:_e++;return[3,2];case 8:_i++;return[3,1];case 9:return[2];}});});};var startUpdating=function(db,collectionName,doc,data,dateArray,geoArray){var parameterValid=true;if(typeof dateArray==='object'&&dateArray.length>0){dateArray.map(function(date){if(data.hasOwnProperty(date)){data[date]=new Date(data[date]._seconds*1000);}
else{console.log('Please check your date parameters!!!',dateArray);parameterValid=false;}});}

@@ -18,0 +18,0 @@ if(typeof geoArray!=='undefined'&&geoArray.length>0){geoArray.map(function(geo){if(data.hasOwnProperty(geo)){data[geo]=new admin.firestore.GeoPoint(data[geo]._latitude,data[geo]._longitude);}

{
"name": "firestore-export-import",
"version": "0.2.6",
"version": "0.2.7",
"description": "NPM package for backup and restore Firebase Firestore",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

# firestore-export-import
[![GitHub version](https://badge.fury.io/gh/dalenguyen%2Ffirestore-backup-restore.svg)](https://badge.fury.io/gh/dalenguyen%2Ffirestore-backup-restore) [![Build Status](https://travis-ci.org/dalenguyen/firestore-backup-restore.svg?branch=master)](https://travis-ci.org/dalenguyen/firestore-backup-restore)
[![GitHub version](https://badge.fury.io/gh/dalenguyen%2Ffirestore-backup-restore.svg)](https://badge.fury.io/gh/dalenguyen%2Ffirestore-backup-restore)
[![Build Status](https://travis-ci.org/dalenguyen/firestore-backup-restore.svg?branch=master)](https://travis-ci.org/dalenguyen/firestore-backup-restore)
[![David badge](https://david-dm.org/dalenguyen/firestore-backup-restore.svg)](https://david-dm.org/dalenguyen/firestore-backup-restore)

@@ -75,2 +77,8 @@ NPM package for backup and restore Firebase Firestore

Remember that, this action doesn't remove the collection. It will override or add new data to the collection. If you want to remove the current collection, you should do it from firebase console or using [firebase firestore:delete](https://firebase.google.com/docs/cli)
```sh
firebase firestore:delete [options] <<path>>
```
#### For local JSON

@@ -105,34 +113,46 @@

{
"test" : {
"first-key" : {
"email" : "dungnq@itbox4vn.com",
"website" : "dalenguyen.me",
"custom" : {
"firstName" : "Dale",
"lastName" : "Nguyen"
},
"test": {
"first-key": {
"website": "dalenguyen.me",
"date": {
"_seconds":1534046400,
"_nanoseconds":0
"_seconds": 1534046400,
"_nanoseconds": 0
},
"custom": {
"lastName": "Nguyen",
"firstName": "Dale"
},
"location": {
"_latitude": 49.290683,
"_longitude": -123.133956
},
"email": "dungnq@itbox4vn.com",
"subCollection": {
"test/first-key/details": {
"33J2A10u5902CXagoBP6": {
"dogId": "2",
"dogName": "hello"
},
"MSZTWEP7Lewx0Qr1Mu5s": {
"dogName": "lala",
"dogId": "2"
}
}
}
},
"second-key" : {
"email" : "test@dalenguyen.me",
"website" : "google.com",
"custom" : {
"firstName" : "Harry",
"lastName" : "Potter"
},
"second-key": {
"website": "google.com",
"date": {
"_seconds":1534262435,
"_nanoseconds":0
"_seconds": 1534262435,
"_nanoseconds": 0
},
"custom": {
"lastName": "Potter",
"firstName": "Harry"
},
"location": {
"_latitude": 49.290683,
"_longitude": -123.133956
}
},
"email": "test@dalenguyen.me"
}

@@ -139,0 +159,0 @@ }

@@ -19,3 +19,3 @@ import * as admin from 'firebase-admin';

udpateCollection(db, dataArray, dateArray, geoArray).then(() => {
updateCollection(db, dataArray, dateArray, geoArray).then(() => {
resolve({ status: true, message: 'Successfully import collection!' });

@@ -35,3 +35,3 @@ }).catch(error => {

udpateCollection(db, dataArray, dateArray, geoArray).then(() => {
updateCollection(db, dataArray, dateArray, geoArray).then(() => {
resolve({ status: true, message: 'Successfully import collection!' });

@@ -56,3 +56,3 @@ }).catch(error => {

*/
const udpateCollection = async (db, dataArray: Array<any>, dateArray: Array<string>, geoArray: Array<string>) => {
const updateCollection = async (db, dataArray: Array<any>, dateArray: Array<string>, geoArray: Array<string>) => {
for (var index in dataArray) {

@@ -66,3 +66,3 @@ var collectionName = index;

await startUpdating(db, collectionName, doc, dataArray[index][doc], dateArray, geoArray);
await udpateCollection(db, subCollections, [], []);
await updateCollection(db, subCollections, [], []);
} else {

@@ -69,0 +69,0 @@ await startUpdating(db, collectionName, doc, dataArray[index][doc], dateArray, geoArray);

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc