Socket
Socket
Sign inDemoInstall

ndjson-to-couchdb

Package Overview
Dependencies
85
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.1.1 to 6.0.0

lib/worker.js

17

bin/cli.js
#!/usr/bin/env node
var ndjson = require('ndjson');
var through = require('through2');
const ndjson = require('hyper-ndjson')

@@ -14,3 +13,4 @@ var config = require('rc')('ndjson-to-couchdb', {

retryTimes: 1,
retryInterval: 100
retryInterval: 100,
concurrency: 1
})

@@ -26,9 +26,6 @@

var to_couch = require('../lib');
const worker = require('../lib/worker')
process.stdin
.pipe(ndjson.parse())
.pipe(to_couch(config))
.pipe(ndjson.stringify())
.pipe(process.stdout)
ndjson(config, process.stdin, process.stdout, worker, function () {
process.exit()
})

@@ -7,42 +7,38 @@ var async = require('async');

module.exports = function(config) {
return through.obj(function(obj, enc, cb) {
module.exports = function(config, obj, cb) {
async.retry({
times: config.retryTimes || 1,
interval: config.retryInterval || 100
}, function (callback) {
async.retry({
times: config.retryTimes || 1,
interval: config.retryInterval || 100
}, function (callback) {
var req_opts = {
method: 'post',
uri: config.url
}
if (config.urlTemplate) {
var compiled = template(req_opts.uri)
req_opts.uri = compiled(obj)
}
if (obj._id || config.key) {
req_opts.method = 'put';
obj._id = obj._id || obj[ config.key ];
req_opts.uri = req_opts.uri + '/' + encodeURIComponent(obj._id);
}
var update = function(){
var prev_rev = obj._rev;
couchr[req_opts.method].call(null, req_opts.uri, obj, function (err, resp) {
if (err) {
if (config.swallowErrors) return callback(null, {ok: false, error: err.toString() })
else return callback(err);
}
var req_opts = {
method: 'post',
uri: config.url
}
if (config.urlTemplate) {
var compiled = template(req_opts.uri)
req_opts.uri = compiled(obj)
}
if (obj._id || config.key) {
req_opts.method = 'put';
obj._id = obj._id || obj[ config.key ];
req_opts.uri = req_opts.uri + '/' + encodeURIComponent(obj._id);
}
var update = function(){
var prev_rev = obj._rev;
couchr[req_opts.method].call(null, req_opts.uri, obj, function (err, resp) {
if (err) {
if (config.swallowErrors) return callback(null, {ok: false, error: err.toString() })
else return callback(err);
}
obj._id = resp.id;
if (config.prev_rev_field) obj[config.prev_rev_field] = prev_rev;
obj._rev = resp.rev;
callback(null, obj);
})
}
if(config.force || config.copy_fields_from_prev_rev) prev(obj, config, update)
else update()
}, cb)
})
obj._id = resp.id;
if (config.prev_rev_field) obj[config.prev_rev_field] = prev_rev;
obj._rev = resp.rev;
callback(null, obj);
})
}
if(config.force || config.copy_fields_from_prev_rev) prev(obj, config, update)
else update()
}, cb)
}

@@ -49,0 +45,0 @@

{
"name": "ndjson-to-couchdb",
"version": "5.1.1",
"version": "6.0.0",
"description": "Stream ndjson to couchdb",

@@ -27,2 +27,3 @@ "bin": "bin/cli.js",

"couchr": "0.0.16",
"hyper-ndjson": "^1.0.0",
"lodash.template": "^4.2.0",

@@ -29,0 +30,0 @@ "ndjson": "^1.3.0",

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc