couchdb-mkdb
Advanced tools
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 @@ }) |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
8459
97
0
3
166
+ Addedrequest@^2.65.0
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.0(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.9.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)