From 832d4c4e0d2c7661c63959a85ef122acc76205f5 Mon Sep 17 00:00:00 2001 From: Dale Nguyen Date: Thu, 19 Mar 2020 17:04:17 -0400 Subject: [PATCH] feat(import): added support for array of locations #42 --- CHANGELOG.md | 6 ++++++ README.md | 14 ++++++++++++-- dist/import.js | 4 ++-- dist/import.js.map | 2 +- package.json | 2 +- src/import.ts | 20 ++++++++++++++------ test/firestore.spec.ts | 6 +++++- test/import-to-firestore.json | 10 ++++++++++ 8 files changed, 51 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 584f2c2..0762524 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,12 @@ --- +## [0.4.0] - 2020-03-19 + +#### - :rocket: [New Feature] + +- Supported import array of locations + ## [0.3.4] - 2020-03-17 #### - :nail_care: [Polish] diff --git a/README.md b/README.md index b930b5d..24310e7 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ Usually the date, location & reference is not converted correctly when you backu // Import options const optons = { dates: ['date1', 'date1.date2', 'date1.date2.date3'], - geos: ['location1', 'location2'], + geos: ['location', 'locations'], refs: ['refKey'] } ``` @@ -109,7 +109,7 @@ firestoreService.initializeApp(serviceAccount, databaseURL) // The array of date, location and reference fields are optional firestoreService.restore('your-file-path.json', { dates: ['date1', 'date1.date2', 'date1.date2.date3'], - geos: ['location1', 'location2'], + geos: ['location', 'locations'], refs: ['refKey', 'arrayRef'] }) ``` @@ -159,6 +159,16 @@ The JSON is formated as below. The collection name is **test**. **first-key** an "_latitude": 49.290683, "_longitude": -123.133956 }, + "locations": [ + { + "_latitude": 50.290683, + "_longitude": -123.133956 + }, + { + "_latitude": 51.290683, + "_longitude": -123.133956 + } + ], "email": "dungnq@itbox4vn.com", "secondRef": "test/second-key", "arrayRef": ["test/second-key", "test/second-key"], diff --git a/dist/import.js b/dist/import.js index a3fabc0..f3b0255 100644 --- a/dist/import.js +++ b/dist/import.js @@ -20,6 +20,6 @@ _c.push(_d);_e=0;_j.label=2;case 2:if(!(_e<_c.length))return[3,12];doc=_c[_e];if _f.push(_g);_h=0;_j.label=8;case 8:if(!(_h<_f.length))return[3,11];subIndex=_f[_h];revivedSubCollection={};subCollectionPath=collectionName+"/"+docId+"/"+subIndex;revivedSubCollection[subCollectionPath]=subCollections[subIndex];return[4,updateCollection(db,revivedSubCollection,options)];case 9:_j.sent();_j.label=10;case 10:_h++;return[3,8];case 11:_e++;return[3,2];case 12:_i++;return[3,1];case 13:return[2];}});});};var startUpdating=function(db,collectionName,docId,data,options){if(options.dates&&options.dates.length>0){updateTime(options.dates,data);} if(options.refs&&options.refs.length>0){options.refs.forEach(function(ref){if(data.hasOwnProperty(ref)){if(Array.isArray(data[ref])){data[ref]=data[ref].map(function(ref){return db.doc(ref);});} else{data[ref]=db.doc(data[ref]);}}});} -if(options.geos&&options.geos.length>0){options.geos.forEach(function(geo){if(data.hasOwnProperty(geo)){data[geo]=new admin.firestore.GeoPoint(data[geo]._latitude,data[geo]._longitude);} -else{console.warn('Please check your geo parameters!!!',options.geos);}});} +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 new admin.firestore.GeoPoint(geoValues._latitude,geoValues._longitude);});} +else{data[geo]=new admin.firestore.GeoPoint(data[geo]._latitude,data[geo]._longitude);}}});} return new Promise(function(resolve,reject){db.collection(collectionName).doc(docId).set(data).then(function(){console.log(docId+" was successfully added to firestore!");resolve({status:true,message:docId+" was successfully added to firestore!"});}).catch(function(error){console.log(error);reject({status:false,message:error.message});});});}; \ No newline at end of file diff --git a/dist/import.js.map b/dist/import.js.map index 224f973..7770e62 100644 --- a/dist/import.js.map +++ b/dist/import.js.map @@ -1 +1 @@ -{"version":3,"file":"import.js","sourceRoot":"","sources":["../src/import.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAwB;AACxB,6B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AAO,CAAC,UAAC,OAAO,EAAE,MAAM;QACjC,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC;aAC1B,GAAG,CAAC,KAAK,CAAC;aACV,GAAG,CAAC,IAAI,CAAC;aACT,IAAI,CAAC;YACJ,OAAO,CAAC,GAAG,CAAI,KAAK,0CAAuC,CAAC,CAAA;YAC5D,OAAO,CAAC;gBACN,MAAM,EAAE,IAAI;gBACZ,OAAO,EAAK,KAAK,0CAAuC;aACzD,CAAC,CAAA;QACJ,CAAC,CAAC;aACD,KAAK,CAAC,UAAA,KAAK;YACV,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;YAClB,MAAM,CAAC;gBACL,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE,KAAK,CAAC,OAAO;aACvB,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"} \ No newline at end of file diff --git a/package.json b/package.json index f17eedf..e183025 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "firestore-export-import", - "version": "0.3.4", + "version": "0.4.0", "description": "NPM package for backup and restore Firebase Firestore", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/import.ts b/src/import.ts index 314fe78..0958acf 100644 --- a/src/import.ts +++ b/src/import.ts @@ -172,12 +172,20 @@ const startUpdating = ( if (options.geos && options.geos.length > 0) { options.geos.forEach(geo => { if (data.hasOwnProperty(geo)) { - data[geo] = new admin.firestore.GeoPoint( - data[geo]._latitude, - data[geo]._longitude - ) - } else { - console.warn('Please check your geo parameters!!!', options.geos) + // array of geo locations + if (Array.isArray(data[geo])) { + data[geo] = data[geo].map(geoValues => { + return new admin.firestore.GeoPoint( + geoValues._latitude, + geoValues._longitude + ) + }) + } else { + data[geo] = new admin.firestore.GeoPoint( + data[geo]._latitude, + data[geo]._longitude + ) + } } }) } diff --git a/test/firestore.spec.ts b/test/firestore.spec.ts index 0ac1a4a..ca55908 100644 --- a/test/firestore.spec.ts +++ b/test/firestore.spec.ts @@ -43,7 +43,7 @@ describe('initializeApp function test', () => { 'test/import-to-firestore.json', { dates: ['date', 'schedule.time', 'three.level.time'], - geos: ['location'], + geos: ['location', 'locations'], refs: ['secondRef', 'arrayRef'] } ) @@ -54,6 +54,10 @@ describe('initializeApp function test', () => { expect(result.test['first-key'].email).is.equal('dungnq@itbox4vn.com') expect(result.test['first-key'].schedule.time._seconds).equals(1534046400) expect(typeof result.test['first-key'].secondRef).is.equal('object') + // locations + expect(result.test['first-key'].location._latitude).equal(49.290683) + expect(result.test['first-key'].locations[0]._latitude).equal(50.290683) + expect(result.test['first-key'].locations[1]._latitude).equal(51.290683) expect( result.test['first-key'].subCollection['test/first-key/details'][ '33J2A10u5902CXagoBP6' diff --git a/test/import-to-firestore.json b/test/import-to-firestore.json index eda104f..08055e0 100644 --- a/test/import-to-firestore.json +++ b/test/import-to-firestore.json @@ -28,6 +28,16 @@ "_latitude": 49.290683, "_longitude": -123.133956 }, + "locations": [ + { + "_latitude": 50.290683, + "_longitude": -123.133956 + }, + { + "_latitude": 51.290683, + "_longitude": -123.133956 + } + ], "email": "dungnq@itbox4vn.com", "secondRef": "test/second-key", "arrayRef": ["test/second-key", "test/second-key"],