@cloudant/couchbackup
Advanced tools
Comparing version 2.3.1 to 2.3.2-SNAPSHOT.1
18
app.js
@@ -87,2 +87,6 @@ // Copyright © 2017, 2018 IBM Corp. All rights reserved. | ||
} | ||
if (opts && typeof opts.requestTimeout !== 'undefined' && !isSafePositiveInteger(opts.requestTimeout)) { | ||
cb(new error.BackupError('InvalidOption', 'Invalid request timeout option, must be a positive integer in the range (0, MAX_SAFE_INTEGER]'), null); | ||
return; | ||
} | ||
if (opts && typeof opts.resume !== 'undefined' && typeof opts.resume !== 'boolean') { | ||
@@ -178,2 +182,3 @@ cb(new error.BackupError('InvalidOption', 'Invalid resume option, must be type boolean'), null); | ||
* @param {number} [opts.bufferSize=500] - Number of documents per batch request. | ||
* @param {number} [opts.requestTimeout=120000] - Milliseconds to wait before retrying a HTTP request. | ||
* @param {string} [opts.iamApiKey] - IAM API key to use to access Cloudant database. | ||
@@ -186,3 +191,3 @@ * @param {string} [opts.log] - Log file name. Default uses a temporary file. | ||
backup: function(srcUrl, targetStream, opts, callback) { | ||
var listenerErrorIndicator = {errored: false}; | ||
var listenerErrorIndicator = { errored: false }; | ||
if (typeof callback === 'undefined' && typeof opts === 'function') { | ||
@@ -246,3 +251,3 @@ callback = opts; | ||
function writeFlushed() { | ||
ee.emit('written', {total: obj.total, time: obj.time, batch: obj.batch}); | ||
ee.emit('written', { total: obj.total, time: obj.time, batch: obj.batch }); | ||
if (logCompletedBatch) { | ||
@@ -276,3 +281,3 @@ logCompletedBatch(obj.batch); | ||
debug('Backup complete - written ' + JSON.stringify(obj)); | ||
const summary = {total: obj.total}; | ||
const summary = { total: obj.total }; | ||
ee.emit('finished', summary); | ||
@@ -303,2 +308,3 @@ if (callback) callback(null, summary); | ||
* @param {number} opts.bufferSize - Number of documents per batch request. Default 500. | ||
* @param {number} opts.requestTimeout - Milliseconds to wait before retrying a HTTP request. Default 120000. | ||
* @param {string} opts.iamApiKey - IAM API key to use to access Cloudant database. | ||
@@ -308,3 +314,3 @@ * @param {backupRestoreCallback} callback - Called on completion. | ||
restore: function(srcStream, targetUrl, opts, callback) { | ||
var listenerErrorIndicator = {errored: false}; | ||
var listenerErrorIndicator = { errored: false }; | ||
if (typeof callback === 'undefined' && typeof opts === 'function') { | ||
@@ -346,3 +352,3 @@ callback = opts; | ||
debug(' restored ', obj.total); | ||
ee.emit('restored', {documents: obj.documents, total: obj.total}); | ||
ee.emit('restored', { documents: obj.documents, total: obj.total }); | ||
}); | ||
@@ -359,3 +365,3 @@ addEventListener(listenerErrorIndicator, writer, 'error', function(err) { | ||
debug('restore complete'); | ||
ee.emit('finished', {total: obj.total}); | ||
ee.emit('finished', { total: obj.total }); | ||
callback(null, obj); | ||
@@ -362,0 +368,0 @@ }); |
@@ -33,2 +33,3 @@ #!/usr/bin/env node | ||
parallelism: program.parallelism, | ||
requestTimeout: program.requestTimeout, | ||
resume: program.resume, | ||
@@ -35,0 +36,0 @@ iamApiKey: program.iamApiKey, |
@@ -29,2 +29,3 @@ #!/usr/bin/env node | ||
parallelism: program.parallelism, | ||
requestTimeout: program.requestTimeout, | ||
iamApiKey: program.iamApiKey, | ||
@@ -31,0 +32,0 @@ iamTokenUrl: program.iamTokenUrl |
@@ -0,1 +1,7 @@ | ||
# 2.4.0 | ||
- [NEW] Added request timeout option. Set via env var `COUCH_REQUEST_TIMEOUT`, | ||
as CLI option `--request-timeout`, or programmatically via | ||
`options.requestTimeout` | ||
# 2.3.1 (2018-06-15) | ||
@@ -2,0 +8,0 @@ |
@@ -149,3 +149,3 @@ // Copyright © 2017, 2018 IBM Corp. All rights reserved. | ||
function onComplete() { | ||
ee.emit('finished', {total: total}); | ||
ee.emit('finished', { total: total }); | ||
} | ||
@@ -219,3 +219,3 @@ | ||
db.server.request( | ||
{method: 'POST', db: db.config.db, path: '_bulk_get', qs: {revs: true}, body: payload}, | ||
{ method: 'POST', db: db.config.db, path: '_bulk_get', qs: { revs: true }, body: payload }, | ||
function(err, body) { | ||
@@ -260,3 +260,3 @@ if (err) { | ||
q.drain = function() { | ||
callback(null, {total: total}); | ||
callback(null, { total: total }); | ||
}; | ||
@@ -263,0 +263,0 @@ } |
@@ -20,3 +20,3 @@ // Copyright © 2017 IBM Corp. All rights reserved. | ||
module.exports = function(onChange) { | ||
var change = new stream.Transform({objectMode: true}); | ||
var change = new stream.Transform({ objectMode: true }); | ||
@@ -23,0 +23,0 @@ change._transform = function(line, encoding, done) { |
@@ -26,2 +26,3 @@ // Copyright © 2017, 2018 IBM Corp. All rights reserved. | ||
bufferSize: 500, | ||
requestTimeout: 120000, | ||
log: tmp.fileSync().name, | ||
@@ -70,2 +71,7 @@ resume: false, | ||
// if we have a specified request timeout | ||
if (typeof process.env.COUCH_REQUEST_TIMEOUT !== 'undefined') { | ||
opts.requestTimeout = parseInt(process.env.COUCH_REQUEST_TIMEOUT); | ||
} | ||
// if we have a specified log file | ||
@@ -72,0 +78,0 @@ if (typeof process.env.COUCH_LOG !== 'undefined') { |
@@ -20,3 +20,3 @@ // Copyright © 2017 IBM Corp. All rights reserved. | ||
module.exports = function() { | ||
var liner = new stream.Transform({objectMode: true}); | ||
var liner = new stream.Transform({ objectMode: true }); | ||
@@ -23,0 +23,0 @@ liner._transform = function(chunk, encoding, done) { |
@@ -21,3 +21,3 @@ // Copyright © 2017 IBM Corp. All rights reserved. | ||
var onLine = function(onCommand, batches) { | ||
var change = new stream.Transform({objectMode: true}); | ||
var change = new stream.Transform({ objectMode: true }); | ||
change._transform = function(line, encoding, done) { | ||
@@ -24,0 +24,0 @@ if (line && line[0] === ':') { |
@@ -21,3 +21,3 @@ // Copyright © 2017 IBM Corp. All rights reserved. | ||
var onLine = function(onCommand, getDocs) { | ||
var change = new stream.Transform({objectMode: true}); | ||
var change = new stream.Transform({ objectMode: true }); | ||
@@ -90,5 +90,5 @@ change._transform = function(line, encoding, done) { | ||
.on('finish', function() { | ||
var obj = {changesComplete: changesComplete, batches: state}; | ||
var obj = { changesComplete: changesComplete, batches: state }; | ||
callback(null, obj); | ||
}); | ||
}; |
@@ -56,2 +56,5 @@ // Copyright © 2017, 2018 IBM Corp. All rights reserved. | ||
defaults.resume) | ||
.option('-t, --request-timeout <n>', | ||
cliutils.getUsage('milliseconds to wait for a response to a HTTP request before retrying the request', defaults.requestTimeout), | ||
Number, defaults.requestTimeout) | ||
.option('-u, --url <url>', | ||
@@ -96,2 +99,5 @@ cliutils.getUsage('URL of the CouchDB/Cloudant server', defaults.url), | ||
Number, defaults.parallelism) | ||
.option('-t, --request-timeout <n>', | ||
cliutils.getUsage('milliseconds to wait for a response to a HTTP request before retrying the request', defaults.requestTimeout), | ||
Number, defaults.requestTimeout) | ||
.option('-u, --url <url>', | ||
@@ -98,0 +104,0 @@ cliutils.getUsage('URL of the CouchDB/Cloudant server', defaults.url), |
@@ -39,18 +39,19 @@ // Copyright © 2017, 2018 IBM Corp. All rights reserved. | ||
if (opts.iamApiKey) { | ||
const iamPluginConfig = {iamApiKey: opts.iamApiKey}; | ||
const iamPluginConfig = { iamApiKey: opts.iamApiKey }; | ||
if (opts.iamTokenUrl) { | ||
iamPluginConfig.iamTokenUrl = opts.iamTokenUrl; | ||
} | ||
pluginsToUse.push({iamauth: iamPluginConfig}); | ||
pluginsToUse.push({ iamauth: iamPluginConfig }); | ||
} else { | ||
pluginsToUse.push('cookieauth'); | ||
} | ||
return cloudant({url: actUrl, | ||
return cloudant({ url: actUrl, | ||
plugins: pluginsToUse, | ||
requestDefaults: { | ||
agent: keepAliveAgent, | ||
headers: {'User-Agent': userAgent}, | ||
gzip: true | ||
}}).use(dbName); | ||
headers: { 'User-Agent': userAgent }, | ||
gzip: true, | ||
timeout: opts.requestTimeout | ||
} }).use(dbName); | ||
} | ||
}; |
@@ -32,3 +32,3 @@ // Copyright © 2017, 2018 IBM Corp. All rights reserved. | ||
// fetch function. | ||
var opts = {limit: options.bufferSize}; | ||
var opts = { limit: options.bufferSize }; | ||
@@ -77,3 +77,3 @@ // To avoid double fetching a document solely for the purposes of getting | ||
function() { return hasErrored || startKey == null; }, | ||
function() { ee.emit('finished', {total: total}); } | ||
function() { ee.emit('finished', { total: total }); } | ||
); | ||
@@ -80,0 +80,0 @@ |
@@ -55,3 +55,3 @@ // Copyright © 2017, 2018 IBM Corp. All rights reserved. | ||
} else if (c.changes) { | ||
var obj = {id: c.id}; | ||
var obj = { id: c.id }; | ||
buffer.push(obj); | ||
@@ -58,0 +58,0 @@ processBuffer(false); |
@@ -23,3 +23,3 @@ // Copyright © 2017, 2018 IBM Corp. All rights reserved. | ||
module.exports = function(db, bufferSize, parallelism, ee) { | ||
const writer = new stream.Transform({objectMode: true}); | ||
const writer = new stream.Transform({ objectMode: true }); | ||
var buffer = []; | ||
@@ -49,3 +49,3 @@ var written = 0; | ||
method: 'POST', | ||
headers: {'content-encoding': 'gzip'} | ||
headers: { 'content-encoding': 'gzip' } | ||
}, function(err) { | ||
@@ -58,3 +58,3 @@ err = error.convertResponseError(err); | ||
written += payload.docs.length; | ||
writer.emit('restored', {documents: payload.docs.length, total: written}); | ||
writer.emit('restored', { documents: payload.docs.length, total: written }); | ||
cb(); | ||
@@ -89,3 +89,3 @@ } | ||
debug(`Adding ${toSend.length} to the write queue.`); | ||
q.push({docs: toSend}, taskCallback); | ||
q.push({ docs: toSend }, taskCallback); | ||
} while (buffer.length >= bufferSize); | ||
@@ -96,3 +96,3 @@ | ||
debug(`Adding remaining ${buffer.length} to the write queue.`); | ||
q.push({docs: buffer}, taskCallback); | ||
q.push({ docs: buffer }, taskCallback); | ||
} | ||
@@ -99,0 +99,0 @@ |
{ | ||
"name": "@cloudant/couchbackup", | ||
"version": "2.3.1", | ||
"version": "2.3.2-SNAPSHOT.1", | ||
"description": "CouchBackup - command-line backup utility for Cloudant/CouchDB", | ||
@@ -25,3 +25,3 @@ "homepage": "https://github.com/cloudant/couchbackup", | ||
"commander": "^2.9.0", | ||
"debug": "~3.1.0", | ||
"debug": "~4.1.0", | ||
"@cloudant/cloudant": "^2.2.0", | ||
@@ -36,11 +36,11 @@ "tmp": "0.0.33" | ||
"devDependencies": { | ||
"eslint": "^4.18.0", | ||
"eslint": "^5.0.0", | ||
"eslint-plugin-import": "^2.8.0", | ||
"eslint-plugin-node": "^6.0.0", | ||
"eslint-plugin-promise": "^3.6.0", | ||
"eslint-plugin-standard": "^3.0.1", | ||
"eslint-plugin-node": "^7.0.1", | ||
"eslint-plugin-promise": "^4.0.0", | ||
"eslint-plugin-standard": "^4.0.0", | ||
"eslint-plugin-react": "^7.7.0", | ||
"eslint-config-standard": "^11.0.0", | ||
"eslint-config-semistandard": "^12.0.1", | ||
"eslint-plugin-header": "^1.0.0", | ||
"eslint-config-standard": "^12.0.0", | ||
"eslint-config-semistandard": "^13.0.0", | ||
"eslint-plugin-header": "^2.0.0", | ||
"jsdoc": "^3.5.2", | ||
@@ -50,5 +50,5 @@ "mocha": "^5.0.0", | ||
"uuid": "^3.0.1", | ||
"tail": "^1.2.1", | ||
"tail": "^2.0.0", | ||
"rewire": "^4.0.0", | ||
"nock": "^9.1.3", | ||
"nock": "^10.0.0", | ||
"http-proxy": "^1.16.2" | ||
@@ -55,0 +55,0 @@ }, |
@@ -191,2 +191,3 @@ # CouchBackup | ||
* `COUCH_BUFFER_SIZE` - the number of documents fetched and restored at once e.g. `100` (default `500`) | ||
* `COUCH_REQUEST_TIMEOUT` - the number of milliseconds to wait for a respose to a HTTP request before retrying the request e.g. `10000` (Default `120000`) | ||
* `COUCH_LOG` - the file to store logging information during backup | ||
@@ -211,2 +212,3 @@ * `COUCH_RESUME` - if `true`, resumes a previous backup from its last known position | ||
* `--buffer-size` - same as `COUCH_BUFFER_SIZE` | ||
* `--request-timeout` - same as `COUCH_REQUEST_TIMEOUT` | ||
* `--log` - same as `COUCH_LOG` | ||
@@ -253,2 +255,3 @@ * `--resume` - same as `COUCH_RESUME` | ||
* `bufferSize`: see `COUCH_BUFFER_SIZE`. | ||
* `requestTimeout`: see `COUCH_REQUEST_TIMEOUT`. | ||
* `log`: see `COUCH_LOG`. | ||
@@ -318,2 +321,3 @@ * `resume`: see `COUCH_RESUME`. | ||
* `bufferSize`: see `COUCH_BUFFER_SIZE`. | ||
* `requestTimeout`: see `COUCH_REQUEST_TIMEOUT`. | ||
* `iamApiKey`: see `CLOUDANT_IAM_API_KEY`. | ||
@@ -320,0 +324,0 @@ * `iamTokenUrl`: may be used with `iamApiKey` to override the default URL for |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
95676
1681
420
1
29
+ Addeddebug@3.2.74.1.1(transitive)
+ Addedms@2.1.3(transitive)
- Removeddebug@3.1.0(transitive)
Updateddebug@~4.1.0