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

nano

Package Overview
Dependencies
Maintainers
1
Versions
155
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nano - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

.npmignore

78

nano.js

@@ -20,4 +20,5 @@ /* Minimal Couch In Node

, qs = require('querystring')
, _ = require('underscore')
, error = require('./error')
, headers = { "content-type": "application/json", "accept": "application/json" }
, headers = { "content-type": "application/json" }
, nano;

@@ -68,5 +69,7 @@

* {opts.db:string} The database name
* {opts.method:string} The HTTP Method
* {opts.doc:string:optional} The document URI, if any
* {opts.body:object|string:optional} The JSON body, if any
* {opts.method:string} The http Method
* {opts.doc:string:optional} The document name
* {opts.att:string:optional} The attachment name
* {opts.content_type:string:optional} The content type, else json will be used
* {opts.body:object|string|binary:optional} The JSON body
* @param {callback:function:optional} The function to callback

@@ -84,8 +87,12 @@ *

if(!callback) { callback = function () { return; }; } // Void Callback
if(opts.doc) { url += "/" + opts.doc; } // Add the document to the URL
if(opts.doc) {
url += "/" + opts.doc; // Add the document to the URL
if(opts.att) { url += "/" + opts.att; } // Add the attachment to the URL
}
if(opts.content_type) { req.headers["content-type"] = opts.content_type; }
if(opts.body) {
if(typeof opts.body === "object") { req.body = JSON.stringify(opts.body); }
else { req.body = opts.body; }
else { req.body = opts.body; } // String or binary
}
req.uri = url + (params ? "?" + qs.stringify(params) : "");
req.uri = url + (_.isEmpty(params) ? "" : "?" + qs.stringify(params));
request(req, function(e,h,b){

@@ -107,15 +114,2 @@ if(e) {

}
/*
* Merges options with params (if any)
*
* @param {opts:object} The request options
* @param {params:object} The aditional query string params
*/
function merge_opts_with_params(opts,params) {
if(params) {
opts.params = params;
}
return opts;
}

@@ -311,8 +305,7 @@ /****************************************************************************

function get_doc(doc_name,params,callback) {
var opts = {db: db_name, doc: doc_name, method: "GET"};
if(typeof params === "function") {
callback = params;
params = null;
params = {};
}
relax(merge_opts_with_params(opts,params),callback);
relax({db: db_name, doc: doc_name, method: "GET", params: params},callback);
}

@@ -329,8 +322,7 @@

function list_docs(params,callback) {
var opts = {db: db_name, doc: "_all_docs", method: "GET"};
if(typeof params === "function") {
callback = params;
params = null;
params = {};
}
relax(merge_opts_with_params(opts,params),callback);
relax({db: db_name, doc: "_all_docs", method: "GET", params: params},callback);
}

@@ -349,4 +341,31 @@

relax({db: db_name, doc: "_bulk_docs", body: docs, method: "POST"},callback);
}
}
/**************************************************************************
* attachment *
**************************************************************************/
/*
* Inserting an attachment
* http://wiki.apache.org/couchdb/HTTP_Document_API
*
* Don't forget that params.rev is required in all cases except when
* creating a new document with a new attachment via this method
*
* @param {doc_name:string} The name of the document
* @param {att_name:string} The name of the attachment
* @param {att:buffer} The attachment data
* @param {content_type:string} The attachment content type
* @param {params:object:optional} Additions to the querystring
*
* @see relax
*/
function insert_att(doc_name,att_name,att,content_type,params,callback) {
if(typeof params === "function") {
callback = params;
params = {};
}
relax({ db: db_name, att: att_name, method: "PUT", content_type: content_type
, doc: doc_name, params: params, body: att},callback);
}
public_functions = { info: function(cb) { get_db(db_name,cb); }

@@ -371,7 +390,6 @@ , replicate: function(target,continuous,cb) {

//, views: {}
// , attachment: { insert: insert_att
// , update: update_att
, attachment: { insert: insert_att
// , get: get_att
// , destroy: destroy_att
// }
}
};

@@ -378,0 +396,0 @@ return public_functions;

{ "name": "nano"
, "description": "NanoCouch is a minimalistic driver for CouchDB built on mikeals/request"
, "homepage": "http://github.com/dscape/nano"
, "version": "0.3.1"
, "version": "0.3.2"
, "author": "Nuno Job <nunojobpinto@gmail.com> (http://nunojob.com)"
, "keywords": ["CouchDB", "data", "request", "json", "nosql", "micro", "nano"]
, "dependencies": { "request": ">=1.9.8", "b64": "1.0.0" }
, "devDependencies": { "async": "~0.1.9", "vows": "~0.5.10" }

@@ -9,0 +8,0 @@ , "main": "./nano.js"

@@ -30,4 +30,4 @@ # nano

// specify the database we are going to use
var alicedb = nano.use("alice");
alicedb.insert("rabbit", {crazy: true}, function(e,h,r){
var alice = nano.use("alice");
alice.insert("rabbit", {crazy: true}, function(e,h,r){
if(e) { throw e; }

@@ -41,7 +41,7 @@ console.log("you have inserted the rabbit.")

// 5: var alicedb = nano.use("alice");
// 5: var alice = nano.use("alice");
in `nano` a callback has always three arguments
// 6: alicedb.insert("rabbit", {crazy: true}, function(e,h,r){
// 6: alice.insert("rabbit", {crazy: true}, function(e,h,r){
// 7: if(e) { throw e; }

@@ -64,2 +64,3 @@ // 8: console.log("you have inserted the rabbit.")

`*` marks optional
`params` are additional querystring parameters

@@ -89,7 +90,8 @@ ### databases (nano)

`db.insert(doc,doc_name*,callback*)`
`db.update(doc_name,rev,doc,callback*)`
`db.destroy(doc_name,rev,callback*)`
`db.get(doc_name,params*,callback*)`
`db.list(params*,callback*)`
`doc.insert(doc,doc_name*,callback*)`
`doc.update(doc_name,rev,doc,callback*)`
`doc.destroy(doc_name,rev,callback*)`
`doc.get(doc_name,params*,callback*)`
`doc.bulk(docs,callback*)`
`doc.list(params*,callback*)`

@@ -100,5 +102,5 @@ #### aliases

`nano.db.get: [db.info(callback*)]`
`nano.db.replicate: [db.replicate(target,continuous*,callback*)]`
`nano.db.compact: [db.compact(callback*)]`
`nano.db.get: [doc.info(callback*)]`
`nano.db.replicate: [doc.replicate(target,continuous*,callback*)]`
`nano.db.compact: [doc.compact(callback*)]`

@@ -121,6 +123,6 @@ ### advanced

this is the same as (assuming `db = nano.use("alice");`):
this is the same as (assuming `alice = nano.use("alice");`):
nano.get("rabbit", {rev: "1-967a00dff5e02add41819138abb3284d"},
function (_,_,b) { console.log(b)
alice.get("rabbit", {rev: "1-967a00dff5e02add41819138abb3284d"},
function (_,_,b) { console.log(b) }
);

@@ -132,5 +134,4 @@

2. explore adding `_changes` feed
3. convenience functions for attachments
4. support views
5. support bulk load
3. `attachments`
4. `views`

@@ -137,0 +138,0 @@ ## contribute

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