Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

couchdb-client

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

couchdb-client - npm Package Compare versions

Comparing version 1.0.8 to 1.0.9

259

index.js

@@ -5,162 +5,161 @@ /*jslint node:true*/

var CouchDBClient = function (options) {
this.options = {};
Object.assign(this.options, options, {
host: '127.0.0.1',
port: '5984'
});
this.place = 'http://' + this.options.host + ':' + this.options.port;
this.options = {};
Object.assign(this.options, options, {
host: '127.0.0.1',
port: '5984'
});
this.place = 'http://' + this.options.host + ':' + this.options.port;
};
function d(name, obj) {
CouchDBClient.prototype[name] = obj;
CouchDBClient.prototype[name] = obj;
}
d('welcome', function (cb) {
if (!cb) {
throw new Error('No callback supplied!');
if (!cb) {
throw new Error('No callback supplied!');
}
request(this.place, function (error, response, data) {
if (response.statusCode === 200) {
cb(null, data);
} else {
cb(error || data);
}
request(this.place, function (error, response, data) {
if (response.statusCode === 200) {
cb(null, data);
} else {
cb(error || data);
}
});
});
});
d('getUUIDs', function (num, cb) {
num = num || 1;
request(this.place + '/_uuids?count=' + num, function (error, response, data) {
data = JSON.parse(data);
if (response.statusCode === 200) {
if (num === 1) {
cb(null, data.uuids[0]);
} else {
cb(null, data.uuids);
}
} else {
cb(error || data);
}
});
num = num || 1;
request(this.place + '/_uuids?count=' + num, function (error, response, data) {
data = JSON.parse(data);
if (response.statusCode === 200) {
if (num === 1) {
cb(null, data.uuids[0]);
} else {
cb(null, data.uuids);
}
} else {
cb(error || data);
}
});
});
d('createDB', function (name, cb) {
request.put(this.place + '/' + name, function (error, response, data) {
data = JSON.parse(data);
if (response.statusCode === 201) {
cb(null, data);
} else {
cb(error || data);
}
});
request.put(this.place + '/' + name, function (error, response, data) {
data = JSON.parse(data);
if (response.statusCode === 201) {
cb(null, data);
} else {
cb(error || data);
}
});
});
d('getDB', function (name, cb) {
request(this.place + '/' + name, function (error, response, data) {
data = JSON.parse(data);
if (response.statusCode === 200) {
cb(null, data);
} else {
cb(error || data);
}
});
request(this.place + '/' + name, function (error, response, data) {
data = JSON.parse(data);
if (response.statusCode === 200) {
cb(null, data);
} else {
cb(error || data);
}
});
});
d('deleteDB', function (name, cb) {
request['delete'](this.place + '/' + name, function (error, response, data) {
data = JSON.parse(data);
if (response.statusCode === 200) {
cb(null, data);
} else {
cb(error || data);
}
});
request['delete'](this.place + '/' + name, function (error, response, data) {
data = JSON.parse(data);
if (response.statusCode === 200) {
cb(null, data);
} else {
cb(error || data);
}
});
});
d('addDoc', function (name, id, data, rev, cb) {
if (typeof rev === 'function') {
cb = rev;
rev = null;
if (typeof rev === 'function') {
cb = rev;
rev = null;
}
if (!cb) {
throw new Error('Callback must be a function');
}
request.put(this.place + '/' + name + '/' + id + (rev ? '?rev=' + rev : ''), {body: JSON.stringify(data)}, function (error, response, data) {
data = JSON.parse(data);
if (response.statusCode === 201) {
cb(null, data);
} else {
cb(error || data);
}
if (!cb) {
throw new Error('Callback must be a function');
}
request.put(this.place + '/' + name + '/' + id + (rev ? '?rev=' + rev : ''), {body: JSON.stringify(data)}, function (error, response, data) {
data = JSON.parse(data);
if (response.statusCode === 201) {
cb(null, data);
} else {
cb(error || data);
}
});
});
});
d('getDoc', function (name, id, cb) {
if (!cb) {
throw new Error('Callback must be a function');
if (!cb) {
throw new Error('Callback must be a function');
}
request(this.place + '/' + name + '/' + id, function (error, response, data) {
data = JSON.parse(data);
var rev = '_' + 'rev';
data.rev = data[rev];
if (response.statusCode === 200) {
cb(null, data);
} else {
cb(error || data);
}
request(this.place + '/' + name + '/' + id, function (error, response, data) {
data = JSON.parse(data);
var rev = '_' + 'rev';
data.rev = data[rev];
if (response.statusCode === 200) {
cb(null, data);
} else {
cb(error || data);
}
});
});
});
d('deleteDoc', function (name, id, rev, cb) {
if (!cb) {
throw new Error('Callback must be a function');
if (!cb) {
throw new Error('Callback must be a function');
}
request.del(this.place + '/' + name + '/' + id + '?rev=' + rev, function (error, response, data) {
data = JSON.parse(data);
if (response.statusCode === 200) {
cb(null, data);
} else {
cb(error || data);
}
request.del(this.place + '/' + name + '/' + id + '?rev=' + rev, function (error, response, data) {
data = JSON.parse(data);
if (response.statusCode === 200) {
cb(null, data);
} else {
cb(error || data);
}
});
});
});
d('addView', function (name, id, obj, rev, cb) {
if (typeof rev === 'function') {
cb = rev;
rev = null;
if (typeof rev === 'function') {
cb = rev;
rev = null;
}
var view = {},
did = '_' + 'id';
view[did] = '_design/' + id;
view.views = obj;
request.put(this.place + '/' + name + '/_design/' + id + (rev ? '?rev=' + rev : ''), {body: JSON.stringify(view)}, function (error, response, data) {
if (error) {
return cb(error);
}
var view = {},
did = '_' + 'id',
i;
view[did] = '_design/' + id;
view.views = obj;
request.put(this.place + '/' + name + '/_design/' + id + (rev ? '?rev=' + rev : ''), {body: JSON.stringify(view)}, function (error, response, data) {
if (error) {
return cb(error);
}
data = JSON.parse(data);
if (response.statusCode.toString().indexOf('20') === 0) {
cb(null, data);
} else {
cb(error || data);
}
});
data = JSON.parse(data);
if (response.statusCode.toString().indexOf('20') === 0) {
cb(null, data);
} else {
cb(error || data);
}
});
});
d('deleteView', function (name, id, rev, cb) {
request.del(this.place + '/' + name + '/_design/' + id + '?rev=' + rev, function (error, response, data) {
if (error) {
return cb(error);
}
data = JSON.parse(data);
if (response.statusCode === 200) {
cb(null, data);
} else {
cb(error || data);
}
});
request.del(this.place + '/' + name + '/_design/' + id + '?rev=' + rev, function (error, response, data) {
if (error) {
return cb(error);
}
data = JSON.parse(data);
if (response.statusCode === 200) {
cb(null, data);
} else {
cb(error || data);
}
});
});
d('useView', function (name, id, view, key, cb) {
request(this.place + '/' + name + '/_design/' + id + '/_view/' + view + (key ? '?key="' + key + '"' : ''), function (error, response, data) {
if (error) {
return cb(error);
}
data = JSON.parse(data);
if (response.statusCode === 200) {
cb(null, data);
} else {
cb(error || data);
}
});
request(this.place + '/' + name + '/_design/' + id + '/_view/' + view + (key ? '?key="' + key + '"' : ''), function (error, response, data) {
if (error) {
return cb(error);
}
data = JSON.parse(data);
if (response.statusCode === 200) {
cb(null, data);
} else {
cb(error || data);
}
});
});
module.exports = CouchDBClient;
{
"name": "couchdb-client",
"version": "1.0.8",
"author": {
"name": "JDB legodudejb@gmail.com"
},
"dependencies": {
"request": "^2.72.0"
},
"description": "A simple couchdb client",
"main": "index.js",
"scripts": {
"test": "mocha test.js"
"devDependencies": {
"unexpected": "^10.13.2"
},

@@ -14,11 +17,16 @@ "keywords": [

],
"author": "JDB legodudejb@gmail.com",
"license": "MIT",
"dependencies": {
"request": "^2.72.0"
"main": "index.js",
"maintainers": [
{
"email": "legodudejb@gmail.com",
"name": "legodude"
}
],
"name": "couchdb-client",
"scripts": {
"test": "mocha test.js"
},
"devDependencies": {
"unexpected": "^10.13.2"
},
"tonicTest": "https://tonicdev.com/npm/couchdb-client"
"tonicTest": "https://tonicdev.com/npm/couchdb-client",
"version": "1.0.9"
}

@@ -7,6 +7,13 @@ # CouchDBClient

- [Documentation](#documentation)
- [CouchDBClient](##couchdbclientoptions)
- [CouchDBClient](#couchdbclientoptions)
- [#welcome](#welcomecallback)
- [#createDB](#createdbname-callback)
- [#getDB](#getdbname-callback)
- [#deleteDB](#deletedbname-callback)
- [#addDoc](#adddocname-id-rev-callback)
- [#getDoc](#getdocname-id-callback)
- [#deleteDoc](#deletedocname-id-rev-callback)
- [#addView](#addviewname-id-obj-callback)
- [#deleteView](#deleteviewname-id-rev-callback)
- [#useView](#useviewname-id-view-key-callback)

@@ -174,4 +181,4 @@ ## Example

## Test
```bash
npm test
```sh
$ npm test
```

@@ -178,0 +185,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc