Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions dist/firestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ var FirestoreBackup = exports.FirestoreBackup = function () {
_classCallCheck(this, FirestoreBackup);

this.options = Object.assign({}, defaultBackupOptions, options);
this.fileWrite = options.fileWrite;

if (this.options.requestCountLimit > 1) {
this.documentRequestLimit = 3; // 3 is the max before diminishing returns
Expand Down Expand Up @@ -197,10 +198,12 @@ var FirestoreBackup = exports.FirestoreBackup = function () {
return Promise.resolve();
}
console.log('Backing up Collection \'' + logPathWithCollection + '\'');
try {
_mkdirp2.default.sync(backupPath);
} catch (error) {
throw new Error('Unable to create backup path for Collection \'' + collection.id + '\': ' + error);
if (!this.fileWrite) {
try {
_mkdirp2.default.sync(backupPath);
} catch (error) {
throw new Error('Unable to create backup path for Collection \'' + collection.id + '\': ' + error);
}
}

return collection.get().then(function (documentSnapshots) {
Expand All @@ -222,10 +225,12 @@ var FirestoreBackup = exports.FirestoreBackup = function () {
return Promise.resolve();
}
console.log('Backing up Document \'' + logPathWithDocument + '\'');
try {
_mkdirp2.default.sync(backupPath);
} catch (error) {
throw new Error('Unable to create backup path for Document \'' + document.id + '\': ' + error);
if (!this.fileWrite) {
try {
_mkdirp2.default.sync(backupPath);
} catch (error) {
throw new Error('Unable to create backup path for Document \'' + document.id + '\': ' + error);
}
}

var fileContents = void 0;
Expand All @@ -242,10 +247,14 @@ var FirestoreBackup = exports.FirestoreBackup = function () {
} catch (error) {
throw new Error('Unable to serialize Document \'' + document.id + '\': ' + error);
}
try {
_fs2.default.writeFileSync(backupPath + '/' + document.id + '.json', fileContents);
} catch (error) {
throw new Error('Unable to write Document \'' + document.id + '\': ' + error);
if (!this.fileWrite) {
try {
_fs2.default.writeFileSync(backupPath + '/' + document.id + '.json', fileContents);
} catch (error) {
throw new Error('Unable to write Document \'' + document.id + '\': ' + error);
}
} else {
this.fileWrite(backupPath + '/' + document.id, fileContents);
}

return document.ref.getCollections().then(function (collections) {
Expand Down
35 changes: 23 additions & 12 deletions dist/firestore.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,11 @@ export class FirestoreBackup {

documentRequestLimit: number;

fileWrite: void;

constructor(options: FirestoreBackupOptions) {
this.options = Object.assign({}, defaultBackupOptions, options)
this.fileWrite = options.fileWrite

if (this.options.requestCountLimit > 1) {
this.documentRequestLimit = 3 // 3 is the max before diminishing returns
Expand Down Expand Up @@ -192,10 +195,12 @@ export class FirestoreBackup {
return Promise.resolve()
}
console.log('Backing up Collection \'' + logPathWithCollection + '\'')
try {
mkdirp.sync(backupPath)
} catch (error) {
throw new Error('Unable to create backup path for Collection \'' + collection.id + '\': ' + error)
if (!this.fileWrite) {
try {
mkdirp.sync(backupPath)
} catch (error) {
throw new Error('Unable to create backup path for Collection \'' + collection.id + '\': ' + error)
}
}

return collection.get()
Expand All @@ -214,10 +219,12 @@ export class FirestoreBackup {
return Promise.resolve()
}
console.log('Backing up Document \'' + logPathWithDocument + '\'')
try {
mkdirp.sync(backupPath)
} catch (error) {
throw new Error('Unable to create backup path for Document \'' + document.id + '\': ' + error)
if (!this.fileWrite) {
try {
mkdirp.sync(backupPath)
} catch (error) {
throw new Error('Unable to create backup path for Document \'' + document.id + '\': ' + error)
}
}

let fileContents: string
Expand All @@ -234,10 +241,14 @@ export class FirestoreBackup {
} catch (error) {
throw new Error('Unable to serialize Document \'' + document.id + '\': ' + error)
}
try {
fs.writeFileSync(backupPath + '/' + document.id + '.json', fileContents)
} catch (error) {
throw new Error('Unable to write Document \'' + document.id + '\': ' + error)
if (!this.fileWrite) {
try {
fs.writeFileSync(backupPath + '/' + document.id + '.json', fileContents)
} catch (error) {
throw new Error('Unable to write Document \'' + document.id + '\': ' + error)
}
} else {
this.fileWrite((backupPath + '/' + document.id), fileContents)
}

return document.ref.getCollections()
Expand Down
10 changes: 6 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ exports.default = function (_options) {
credential: _firebaseAdmin2.default.credential.cert(accountCredentialsContents)
});

try {
_mkdirp2.default.sync(options.backupPath);
} catch (error) {
throw new Error('Unable to create backup path \'' + options.backupPath + '\': ' + error);
if (!options.fileWrite) {
try {
_mkdirp2.default.sync(options.backupPath);
} catch (error) {
throw new Error('Unable to create backup path \'' + options.backupPath + '\': ' + error);
}
}

options.database = _firebaseAdmin2.default.firestore();
Expand Down
13 changes: 8 additions & 5 deletions dist/index.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export type BackupOptions = {|
prettyPrintJSON: boolean,
requestCountLimit: number,
exclude: Array<string>,
excludePatterns: Array<RegExp>
excludePatterns: Array<RegExp>,
fileWrite: void
|}

export default function(_options: BackupOptions) {
Expand All @@ -42,10 +43,12 @@ export default function(_options: BackupOptions) {
credential: Firebase.credential.cert(accountCredentialsContents)
})

try {
mkdirp.sync(options.backupPath)
} catch (error) {
throw new Error('Unable to create backup path \'' + options.backupPath + '\': ' + error)
if (!options.fileWrite) {
try {
mkdirp.sync(options.backupPath)
} catch (error) {
throw new Error('Unable to create backup path \'' + options.backupPath + '\': ' + error)
}
}

options.database = Firebase.firestore()
Expand Down
35 changes: 23 additions & 12 deletions lib/firestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,11 @@ export class FirestoreBackup {

documentRequestLimit: number;

fileWrite: void;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an optional function type?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm trying to think of what would be a more apt member name, technically this isn't a fileWrite function anymore, it's an any-way-we-want-to-handle-the-contents function now.


constructor(options: FirestoreBackupOptions) {
this.options = Object.assign({}, defaultBackupOptions, options)
this.fileWrite = options.fileWrite

if (this.options.requestCountLimit > 1) {
this.documentRequestLimit = 3 // 3 is the max before diminishing returns
Expand Down Expand Up @@ -192,10 +195,12 @@ export class FirestoreBackup {
return Promise.resolve()
}
console.log('Backing up Collection \'' + logPathWithCollection + '\'')
try {
mkdirp.sync(backupPath)
} catch (error) {
throw new Error('Unable to create backup path for Collection \'' + collection.id + '\': ' + error)
if (!this.fileWrite) {
try {
mkdirp.sync(backupPath)
} catch (error) {
throw new Error('Unable to create backup path for Collection \'' + collection.id + '\': ' + error)
}
}

return collection.get()
Expand All @@ -214,10 +219,12 @@ export class FirestoreBackup {
return Promise.resolve()
}
console.log('Backing up Document \'' + logPathWithDocument + '\'')
try {
mkdirp.sync(backupPath)
} catch (error) {
throw new Error('Unable to create backup path for Document \'' + document.id + '\': ' + error)
if (!this.fileWrite) {
try {
mkdirp.sync(backupPath)
} catch (error) {
throw new Error('Unable to create backup path for Document \'' + document.id + '\': ' + error)
}
}

let fileContents: string
Expand All @@ -234,10 +241,14 @@ export class FirestoreBackup {
} catch (error) {
throw new Error('Unable to serialize Document \'' + document.id + '\': ' + error)
}
try {
fs.writeFileSync(backupPath + '/' + document.id + '.json', fileContents)
} catch (error) {
throw new Error('Unable to write Document \'' + document.id + '\': ' + error)
if (!this.fileWrite) {
try {
fs.writeFileSync(backupPath + '/' + document.id + '.json', fileContents)
} catch (error) {
throw new Error('Unable to write Document \'' + document.id + '\': ' + error)
}
} else {
this.fileWrite((backupPath + '/' + document.id), fileContents)
}

return document.ref.getCollections()
Expand Down
13 changes: 8 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export type BackupOptions = {|
prettyPrintJSON: boolean,
requestCountLimit: number,
exclude: Array<string>,
excludePatterns: Array<RegExp>
excludePatterns: Array<RegExp>,
fileWrite: void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also be an optional function type?

|}

export default function(_options: BackupOptions) {
Expand All @@ -42,10 +43,12 @@ export default function(_options: BackupOptions) {
credential: Firebase.credential.cert(accountCredentialsContents)
})

try {
mkdirp.sync(options.backupPath)
} catch (error) {
throw new Error('Unable to create backup path \'' + options.backupPath + '\': ' + error)
if (!options.fileWrite) {
try {
mkdirp.sync(options.backupPath)
} catch (error) {
throw new Error('Unable to create backup path \'' + options.backupPath + '\': ' + error)
}
}

options.database = Firebase.firestore()
Expand Down
Loading