From 05a291d6c1134fb908dc90fbb24d25146364de9d Mon Sep 17 00:00:00 2001 From: Dale Nguyen Date: Tue, 15 Sep 2020 16:59:29 -0400 Subject: [PATCH] Updated packages + changelog --- CHANGELOG.md | 10 ++++++++++ README.md | 13 +++++++++++-- dist/helper.d.ts | 2 ++ dist/helper.js | 8 +++++--- dist/helper.js.map | 2 +- dist/import.js | 1 + dist/import.js.map | 2 +- package.json | 6 +++--- test/firestore.spec.ts | 41 +++++++++++++++++++++++++++++++++++++---- yarn.lock | 27 +++++++++++---------------- 10 files changed, 82 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2594452..b674c6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,16 @@ --- +## ## [0.8.0] - 2020-09-15 + +#### - :rocket: [New Feature] + +- Added Automatic Timestamp Parsing (Thank @benwinding) + +#### - :nail_care: [Polish] + +- Updated firebase-admin packages (9.2.0) + ## ## [0.7.0] - 2020-09-04 #### - :rocket: [New Feature] diff --git a/README.md b/README.md index 44ddd4f..6e76395 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,17 @@ const options = { dates: ['date1', 'date1.date2', 'date1.date2.date3'], geos: ['location', 'locations'], refs: ['refKey'], - nested: true, // look up the data keys also in nested maps +}; +``` + +If you don't want to specify `dates`, you can use another parameter in order to transform fields to date auttomatically. + +```javascript +// Import options with auto parse date +const options = { + autoParseDates: true // use this one in stead of dates: [...] + geos: ['location', 'locations'], + refs: ['refKey'], }; ``` @@ -101,7 +111,6 @@ After that, the data will be converted based on their types. ```javascript // In your index.js - const firestoreService = require('firestore-export-import'); const serviceAccount = require('./serviceAccountKey.json'); diff --git a/dist/helper.d.ts b/dist/helper.d.ts index 66195ee..a58eb9f 100644 --- a/dist/helper.d.ts +++ b/dist/helper.d.ts @@ -1,5 +1,6 @@ export interface IImportOptions { dates?: string[]; + autoParseDates?: boolean; geos?: string[]; refs?: string[]; } @@ -18,3 +19,4 @@ export declare const makeTime: (firebaseTimestamp: { * @param callback */ export declare const traverseObjects: (data: any, callback: Function) => void; +export declare function parseAndConvertDates(data: object): void; diff --git a/dist/helper.js b/dist/helper.js index 813372a..7f128ae 100644 --- a/dist/helper.js +++ b/dist/helper.js @@ -1,4 +1,6 @@ -"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.traverseObjects=exports.makeTime=void 0;exports.makeTime=function(firebaseTimestamp){if(!firebaseTimestamp||!firebaseTimestamp._seconds){return null;} -return new Date(firebaseTimestamp._seconds*1000);};var isObject=function(test){return(test===null||test===void 0?void 0:test.constructor)===Object;};exports.traverseObjects=function(data,callback){for(var _i=0,_a=Object.entries(data);_i<_a.length;_i++){var _b=_a[_i],key=_b[0],value=_b[1];if(!isObject(value)){continue;} +"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.parseAndConvertDates=exports.traverseObjects=exports.makeTime=void 0;exports.makeTime=function(firebaseTimestamp){if(!firebaseTimestamp||!firebaseTimestamp._seconds){return null;} +return new Date(firebaseTimestamp._seconds*1000);};var isObject=function(test){return(test===null||test===void 0?void 0:test.constructor)===Object;};var isArray=function(test){return Array.isArray(test);};exports.traverseObjects=function(data,callback){for(var _i=0,_a=Object.entries(data);_i<_a.length;_i++){var _b=_a[_i],key=_b[0],value=_b[1];if(!isObject(value)&&!isArray(value)){continue;} var checkResult=callback(value);if(checkResult){data[key]=checkResult;continue;} -exports.traverseObjects(data[key],callback);}}; \ No newline at end of file +exports.traverseObjects(data[key],callback);}};function parseAndConvertDates(data){exports.traverseObjects(data,function(value){var isTimeStamp=typeof value==="object"&&value.hasOwnProperty("_seconds")&&value.hasOwnProperty("_nanoseconds");if(isTimeStamp){return exports.makeTime(value);} +return null;});} +exports.parseAndConvertDates=parseAndConvertDates; \ No newline at end of file diff --git a/dist/helper.js.map b/dist/helper.js.map index 3f0865d..8923ba3 100644 --- a/dist/helper.js.map +++ b/dist/helper.js.map @@ -1 +1 @@ -{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":";;;AAMA;;;GAGG;AAEU,QAAA,QAAQ,GAAG,UAAC,iBAGxB;IACC,IAAI,CAAC,iBAAiB,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE;QACrD,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,IAAI,IAAI,CAAC,iBAAiB,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAA;AACpD,CAAC,CAAA;AAED;;;GAGG;AACH,IAAM,QAAQ,GAAG,UAAC,IAAS;IACzB,OAAO,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,MAAK,MAAM,CAAA;AACrC,CAAC,CAAA;AAED;;;;;GAKG;AACU,QAAA,eAAe,GAAG,UAAC,IAAS,EAAE,QAAkB;IAC3D,KAA2B,UAAoB,EAApB,KAAA,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAApB,cAAoB,EAApB,IAAoB,EAAE;QAAtC,IAAA,WAAY,EAAX,GAAG,QAAA,EAAE,KAAK,QAAA;QACpB,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;YACpB,SAAQ;SACT;QAED,IAAM,WAAW,GAAQ,QAAQ,CAAC,KAAK,CAAC,CAAA;QACxC,IAAI,WAAW,EAAE;YACf,IAAI,CAAC,GAAG,CAAC,GAAG,WAAW,CAAA;YACvB,SAAQ;SACT;QAED,uBAAe,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAA;KACrC;AACH,CAAC,CAAA"} \ No newline at end of file +{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":";;;AAOA;;;GAGG;AAEU,QAAA,QAAQ,GAAG,UAAC,iBAGxB;IACC,IAAI,CAAC,iBAAiB,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE;QACrD,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,IAAI,IAAI,CAAC,iBAAiB,CAAC,QAAQ,GAAG,IAAI,CAAC,C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dist/import.js b/dist/import.js index 495b13b..3d5ad6b 100644 --- a/dist/import.js +++ b/dist/import.js @@ -19,6 +19,7 @@ _f.push(_g);_h=0;_j.label=8;case 8:if(!(_h<_f.length))return[3,11];subIndex=_f[_ else{data[date]=helper_1.makeTime(data[date]);}} if(date.indexOf('.')>-1){helper_1.traverseObjects(data,function(value){if(!value.hasOwnProperty('_seconds')){return null;} return helper_1.makeTime(value);});}});} +if(options.autoParseDates){helper_1.parseAndConvertDates(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){var makeGeoPoint_1=function(geoValues){if(!geoValues._latitude||!geoValues._longitude){return null;} diff --git a/dist/import.js.map b/dist/import.js.map index ba9c7d8..9bafd8f 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,6BAAmC;AACnC,oDAAuC;AACvC,mCAAoE;AAEpE;;;;;GAKG;AACU,QAAA,OAAO,GAAG,UACrB,QAAgB,EAChB,OAAuB;IAEvB,IAAM,EAAE,GAAG,KAAK,CAAC,SAAS,EAAE,CAAA;IAE5B,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QACjC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;YAChC,IAAI,OAAO,GAAG,QAAQ,CAAA;YAEtB,gBAAgB,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC;iBACnC,IAAI,CAAC;gBACJ,OAAO,CAAC;oBACN,MAAM,EAAE,IAAI;oBACZ,OAAO,EAAE,mCAAmC;iBAC7C,CAAC,CAAA;YACJ,CAAC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;iBAChE;qBAAM;oBACL,IAAI,CAAC,GAAG,CAAC,GAAG,cAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;iBACpC;aACF;YAED,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE;gBACzB,wBAAe,CAAC,IAAI,EAAE,UAAA,KAAK;oBACzB,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,EAAE;wBACtC,OAAO,IAAI,CAAA;qBACZ;oBACD,OAAO,cAAY,CAAC,KAAK,CAAC,CAAA;gBAC5B,CAAC,CAAC,CAAA;aACH;QACH,CAAC,CAAC,CAAA;KACH;IAED,OAAO,IAAI,OAAO,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 +{"version":3,"file":"import.js","sourceRoot":"","sources":["../src/import.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAwB;AACxB,6BAAmC;AACnC,oDAAuC;AACvC,mCAA0F;AAE1F;;;;;GAKG;AACU,QAAA,OAAO,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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 f1f5f87..b77f625 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "firestore-export-import", - "version": "0.7.0", + "version": "0.8.0", "description": "NPM package for backup and restore Firebase Firestore", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -31,7 +31,7 @@ "devDependencies": { "@types/chai": "^4.2.12", "@types/mocha": "^8.0.3", - "@types/node": "^14.6.4", + "@types/node": "^14.10.2", "chai": "^4.2.0", "jsmin": "^1.0.1", "minimist": "^1.2.5", @@ -42,7 +42,7 @@ "typescript": "^4.0.2" }, "dependencies": { - "firebase-admin": "^9.1.1" + "firebase-admin": "^9.2.0" }, "resolutions": { "minimist": "1.2.5" diff --git a/test/firestore.spec.ts b/test/firestore.spec.ts index 9ceb365..e47051d 100644 --- a/test/firestore.spec.ts +++ b/test/firestore.spec.ts @@ -39,7 +39,7 @@ describe('initializeApp function test', () => { expect(Object.keys(all).length).is.equal(2); }); - it('Restore data with document id', async () => { + it('Restore data with document id - without autoParseDates', async () => { let status = await firestoreService.restore( 'test/import-to-firestore.json', { @@ -72,6 +72,39 @@ describe('initializeApp function test', () => { ).is.equal('hello'); }); + it('Restore data with document id - with autoParseDates', async () => { + let status = await firestoreService.restore( + 'test/import-to-firestore.json', + { + autoParseDates: true, + geos: ['location', 'locations', 'locationNested.geopoints'], + refs: ['secondRef', 'arrayRef', 'nestedRef.secondRef'], + } + ); + expect(status.status).ok; + + const result = await firestoreService.backup('test'); + + expect(result.test['first-key'].email).is.equal('dungnq@itbox4vn.com'); + expect(result.test['first-key'].schedule.time._seconds).equals(1534046400); + expect(result.test['first-key'].three.level.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'].locationNested.geopoint._latitude).equal( + 49.290683 + ); + expect( + result.test['first-key'].subCollection['test/first-key/details'][ + '33J2A10u5902CXagoBP6' + ].dogName + ).is.equal('hello'); + }); + it('Restore data as an array without document id', async () => { let status = await firestoreService.restore( 'test/import-array-to-firestore.json' @@ -122,8 +155,8 @@ describe('initializeApp function test', () => { date: { _seconds: 1534046400, _nanoseconds: 0, - } - } + }, + }, }, }; parseAndConvertDates(data); @@ -137,7 +170,7 @@ describe('initializeApp function test', () => { { _seconds: 1534046400, _nanoseconds: 0, - } + }, ], }; parseAndConvertDates(data); diff --git a/yarn.lock b/yarn.lock index 271d786..727154a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -94,7 +94,7 @@ resolved "https://registry.yarnpkg.com/@google-cloud/promisify/-/promisify-2.0.3.tgz#f934b5cdc939e3c7039ff62b9caaf59a9d89e3a8" integrity sha512-d4VSA86eL/AFTe5xtyZX+ePUjE8dIFu2T8zmdeNBSa5/kNgXPCx/o/wbFNHAGLJdGnk1vddRuMESD9HbOC8irw== -"@google-cloud/storage@^5.0.0": +"@google-cloud/storage@^5.3.0": version "5.3.0" resolved "https://registry.yarnpkg.com/@google-cloud/storage/-/storage-5.3.0.tgz#cf86683911cce68829e46de544abb41947d29da2" integrity sha512-3t5UF3SZ14Bw2kcBHubCai6EIugU2GnQOstYWVSFuoO8IJ94RAaIOPq/dtexvQbUTpBTAGpd5smVR9WPL1mJVw== @@ -242,10 +242,10 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-13.13.16.tgz#66f2177047b61131eaac18c47eb25d6f1317070a" integrity sha512-dJ9vXxJ8MEwzNn4GkoAGauejhXoKuJyYKegsA6Af25ZpEDXomeVXt5HUWUNVHk5UN7+U0f6ghC6otwt+7PdSDg== -"@types/node@^14.6.4": - version "14.6.4" - resolved "https://registry.yarnpkg.com/@types/node/-/node-14.6.4.tgz#a145cc0bb14ef9c4777361b7bbafa5cf8e3acb5a" - integrity sha512-Wk7nG1JSaMfMpoMJDKUsWYugliB2Vy55pdjLpmLixeyMi7HizW2I/9QoxsPCkXl3dO+ZOVqPumKaDUv5zJu2uQ== +"@types/node@^14.10.2": + version "14.10.2" + resolved "https://registry.yarnpkg.com/@types/node/-/node-14.10.2.tgz#9b47a2c8e4dabd4db73b57e750b24af689600514" + integrity sha512-IzMhbDYCpv26pC2wboJ4MMOa9GKtjplXfcAqrMeNJpUUwpM/2ATt2w1JPUXwS6spu856TvKZL2AOmeU2rAxskw== abort-controller@^3.0.0: version "3.0.0" @@ -823,20 +823,20 @@ find-up@^4.1.0: locate-path "^5.0.0" path-exists "^4.0.0" -firebase-admin@^9.1.1: - version "9.1.1" - resolved "https://registry.yarnpkg.com/firebase-admin/-/firebase-admin-9.1.1.tgz#153aff515140a41d92ebc51231c12c7b2f4c3e69" - integrity sha512-HkzY9yN/kOe1EQgjheURAQ4pFBerI54TBL0+nj1fwzKnAnGCpcI73Bbwx99Pk3u2x4rj6bDcsZfz9bA8y7DWtQ== +firebase-admin@^9.2.0: + version "9.2.0" + resolved "https://registry.yarnpkg.com/firebase-admin/-/firebase-admin-9.2.0.tgz#df5176e2d0c5711df6dbf7012320492a703538ea" + integrity sha512-LhnMYl71B4gP1FlTLfwaYlOWhBCAcNF+byb2CPTfaW/T4hkp4qlXOgo2bws/zbAv5X9GTFqGir3KexMslVGsIA== dependencies: "@firebase/database" "^0.6.10" "@firebase/database-types" "^0.5.2" "@types/node" "^10.10.0" dicer "^0.3.0" jsonwebtoken "^8.5.1" - node-forge "^0.9.1" + node-forge "^0.10.0" optionalDependencies: "@google-cloud/firestore" "^4.0.0" - "@google-cloud/storage" "^5.0.0" + "@google-cloud/storage" "^5.3.0" flat@^4.1.0: version "4.1.0" @@ -1527,11 +1527,6 @@ node-forge@^0.10.0: resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.10.0.tgz#32dea2afb3e9926f02ee5ce8794902691a676bf3" integrity sha512-PPmu8eEeG9saEUvI97fm4OYxXVB6bFvyNTyiUOBichBpFG8A1Ljw3bY62+5oOjDEMHRnd0Y7HQ+x7uzxOzC6JA== -node-forge@^0.9.1: - version "0.9.2" - resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.9.2.tgz#b35a44c28889b2ea55cabf8c79e3563f9676190a" - integrity sha512-naKSScof4Wn+aoHU6HBsifh92Zeicm1GDQKd1vp3Y/kOi8ub0DozCa9KpvYNCXslFHYRmLNiqRopGdTGwNLpNw== - normalize-path@^3.0.0, normalize-path@~3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"