Socket
Socket
Sign inDemoInstall

couchdb-mkdb

Package Overview
Dependencies
56
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.1 to 2.0.0

48

index.js
'use strict';
var http = require('http');
var EventEmitter = require('events');
var request = require('request');
var xtend = require('xtend');

@@ -22,6 +22,2 @@ var es = require('event-stream');

let security = opts.security;
let jsonHeaders = {
'Content-Type': 'application/json',
'Accept': 'application/json'
};
let emitter = new EventEmitter();

@@ -37,20 +33,16 @@ delete opts.security;

function createDb() {
http.request(xtend(opts, {
method: 'PUT',
path: '/' + name,
headers: jsonHeaders
}))
.on('error', emitter.emit.bind(emitter, 'error'))
.on('response', function(r) {
if (r.statusCode !== 201) {
emitter.emit('errorResponse', r);
return emitter.emit('response', r);
}
if (!security) {
emitter.emit('response', r);
return emitter.emit('success');
}
updateSecurity();
})
.end();
request.put('/' + name, xtend(opts, {json: true}))
.on('error', emitter.emit.bind(emitter, 'error'))
.on('response', function(r) {
if (r.statusCode !== 201) {
emitter.emit('errorResponse', r);
return emitter.emit('response', r);
}
if (!security) {
emitter.emit('response', r);
return emitter.emit('success');
}
updateSecurity();
})
.end();
}

@@ -62,11 +54,3 @@

function updateSecurity() {
let r = http.request(xtend(opts, {
method: 'PUT',
path: '/' + name + '/_security',
headers: jsonHeaders
}));
es.readArray([security])
.pipe(es.stringify())
.pipe(r)
request.put('/' + name + '/_security', xtend(opts, {json: security}))
.on('error', emitter.emit.bind(emitter, 'error'))

@@ -73,0 +57,0 @@ .on('response', function(r) {

{
"name": "couchdb-mkdb",
"version": "1.1.1",
"version": "2.0.0",
"dependencies": {

@@ -5,0 +5,0 @@ "event-stream": {

{
"name": "couchdb-mkdb",
"version": "1.1.1",
"version": "2.0.0",
"description": "Utility to create couchdb databases easier.",
"main": "index.js",
"scripts": {
"test": "tape test/*.js | faucet",
"test": "npm run jshint && tape test/*.js | faucet",
"jshint": "jshint ."

@@ -14,2 +14,3 @@ },

"event-stream": "^3.3.2",
"request": "^2.65.0",
"xtend": "^4.0.1"

@@ -16,0 +17,0 @@ },

@@ -27,4 +27,4 @@ # couchdb-mkdb

// ... all other options are passed to the underlaying `request` function.
// See [http.request()](https://nodejs.org/api/http.html#http_http_request_options_callback)
host: app.get('couchdb'),
// See https://github.com/request/request#requestoptions-callback
baseUrl: app.get('couchdb'),
auth: app.get('auth')

@@ -68,3 +68,3 @@ };

All other options are passed to the underlaying
[http.request()](https://nodejs.org/api/http.html#http_http_request_options_callback)
[request()](https://github.com/request/request#requestoptions-callback)
function.

@@ -88,3 +88,12 @@

### v2.0
`mkdb` now uses [request](https://github.com/request/request) as transport
engine. Therefore the options you can pass are similar to
[request](https://github.com/request/request)'s options. See
[docs](https://github.com/request/request#requestoptions-callback).
### v1.1
The first version had an 'errorResponse' event. This has now been deprecated.
Use the 'response' event instead and check the statusCode.

@@ -28,3 +28,3 @@ var stream = require('stream');

var responseCalled = false;
mkdb('db1', {port: '5984'})
mkdb('db1', {baseUrl: 'http://localhost:5984'})
.on('response', function() {

@@ -40,3 +40,3 @@ responseCalled = true;

test('error-response test', t => {
mkdb('dbfail', {port: '5984'})
mkdb('dbfail', {baseUrl: 'http://localhost:5984'})
.on('response', () => {

@@ -48,3 +48,3 @@ t.end();

test('security fail test', t => {
mkdb('dbsecurity', {port: '5984', security: {}})
mkdb('dbsecurity', {baseUrl: 'http://localhost:5984', security: {}})
.on('response', () => {

@@ -57,4 +57,5 @@ t.end();

var responseCalled = false;
mkdb('dbsecuritysuccess', {port: '5984', security: {}})
.on('response', function() {
mkdb('dbsecuritysuccess', {baseUrl: 'http://localhost:5984', security: {}})
.on('response', function(res) {
t.assert(res.body == null);
responseCalled = true;

@@ -61,0 +62,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