Socket
Socket
Sign inDemoInstall

nano

Package Overview
Dependencies
Maintainers
2
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 3.0.9 to 3.1.0

tests/doc/copy.js

83

nano.js

@@ -75,3 +75,3 @@ /* minimal couch in node

*
* @param {opts:object|string} request options;
* @param {opts:object|string} request options;
* e.g. {db: "test", method: "GET"}

@@ -85,3 +85,4 @@ * {opts.db:string} database name

* {opts.content_type:string:optional} content type, default to json
* {opts.body:object|string|binary:optional} document or attachment body
* {opts.body:object|string|binary:optional} document or attachment
* body
* {opts.encoding:string:optional} encoding for attachments

@@ -123,3 +124,3 @@ * @param {callback:function:optional} function to call back

// check github.com/mikeal/request for docs
if (opts.jar) {
if (opts.jar) {
req.jar = opts.jar;

@@ -144,3 +145,3 @@ }

if(!/^_design/.test(opts.doc)) {
try {
try {
req.uri += "/" + encodeURIComponent(opts.doc);

@@ -188,3 +189,3 @@ }

try { params[key] = JSON.stringify(params[key]); }
catch (err) {
catch (err) {
return errs.handle(errs.merge(err,

@@ -206,3 +207,3 @@ { "note" : "bad params: " + key + " = " + params[key]

try {
try {
req.uri += "?" + qs.stringify(params);

@@ -234,3 +235,3 @@ }

});
} catch (err3) {
} catch (err3) {
return errs.handle(errs.merge(err3,

@@ -246,6 +247,7 @@ { "note" : "body seems to be invalid json"

if(opts.form) {
req.headers['content-type'] = 'application/x-www-form-urlencoded; charset=utf-8';
req.headers['content-type'] =
'application/x-www-form-urlencoded; charset=utf-8';
req.body = qs.stringify(opts.form).toString('utf8');
}
log(req);

@@ -257,3 +259,3 @@

return request(req);
} catch (err4) {
} catch (err4) {
return errs.handle(errs.merge(err4,

@@ -309,3 +311,3 @@ { "note" : "request threw when you tried to stream"

return stream;
} catch(err5) {
} catch(err5) {
return errs.merge(err5,

@@ -474,4 +476,4 @@ { "note" : "request threw when you tried to create the object"

* https://github.com/iriscouch/follow
*
*
*
* @see relax

@@ -629,3 +631,3 @@ */

*
* e.g. db2.head("foo", function (e,b) {
* e.g. db2.head("foo", function (e,b,h) {
* console.log(e,b,h);

@@ -646,2 +648,39 @@ * return;

/*
* copy a document to a new document, or overwrite an existing document
* [1]: http://wiki.apache.org/couchdb/HTTP_Document_API#COPY
*
* e.g. db2.copy("source", "target", { overwrite: true }, function(e,b,h) {
* console.log(e,b,h);
* return;
* });
*
* @param {doc_src:string} source document name
* @param {doc_dest:string} destination document name
* @param {opts:object:optional} set overwrite preference
*
* @see relax
*/
function copy_doc(doc_src, doc_dest, opts, callback) {
if(typeof opts === "function") {
callback = opts;
opts = {};
}
var params =
{ db: db_name, doc: doc_src, method: "COPY"
, headers: { "Destination": doc_dest }
};
if(opts.overwrite) {
return head_doc(doc_dest, function (e,b,h) {
if (typeof h.etag === "string") {
params.headers.Destination += "?rev=" +
h.etag.substring(1, h.etag.length - 1);
}
return relax(params, callback);
});
} else {
return relax(params, callback);
}
}
/*
* lists all the documents in a couchdb database

@@ -669,3 +708,4 @@ *

* @param {doc_names:object} document keys as per the couchdb api[1]
* @param {params:object} additions to the querystring, note that include_docs is always set to true
* @param {params:object} additions to the querystring, note
* that include_docs is always set to true
*

@@ -722,3 +762,3 @@ * @see get_doc

*/
function update_with_handler_doc(design_name, update_name,
function update_with_handler_doc(design_name, update_name,
doc_name, body, callback) {

@@ -729,3 +769,3 @@ if(typeof body === "function") {

}
var update_path = '_design/' + design_name + '/_update/' +
var update_path = '_design/' + design_name + '/_update/' +
update_name + '/' + doc_name;

@@ -831,4 +871,4 @@ return relax(

}
, compact : function(cb) {
return compact_db(db_name,cb);
, compact : function(cb) {
return compact_db(db_name,cb);
}

@@ -845,2 +885,3 @@ , changes : function(params,cb) {

, head : head_doc
, copy : copy_doc
, destroy : destroy_doc

@@ -851,3 +892,3 @@ , bulk : bulk_docs

, config : {url: cfg.url, db: db_name}
, attachment :
, attachment :
{ insert : insert_att

@@ -870,3 +911,3 @@ , get : get_att

// server level exports
public_functions =
public_functions =
{ db :

@@ -935,3 +976,3 @@ { create : create_db

// nano('http://couch.nodejitsu.com/db1')
// nano('http://couch.nodejitsu.com/db1')
// should return a database

@@ -938,0 +979,0 @@ // nano('http://couch.nodejitsu.com')

@@ -5,3 +5,3 @@ { "name" : "nano"

, "repository" : "git://github.com/dscape/nano"
, "version" : "3.0.9"
, "version" : "3.1.0"
, "author" : "Nuno Job <nunojobpinto@gmail.com> (http://nunojob.com)"

@@ -25,3 +25,3 @@ , "contributors" :

, "Dominique Sandoz <dominique.sandoz@gmail.com>"
, "John Lancaster (http://jlank.com)"
, "John Lancaster <john.k.lancaster@gmail.com> (http://jlank.com)"
]

@@ -28,0 +28,0 @@ , "keywords" :

@@ -330,2 +330,15 @@ # nano

### db.copy(src_doc, dest_doc, opts, [callback])
`copy` the contents (and attachments) of a document
to a new document, or overwrite an existing target document
``` js
alice.copy('rabbit', 'rabbit2', { overwrite: true }, function(err, _, headers) {
if (!err)
console.log(headers);
});
```
### db.bulk(docs, [params], [callback])

@@ -553,2 +566,3 @@

* article: [securing a site with couchdb cookie authentication using node.js and nano](http://mahoney.eu/2012/05/23/couchdb-cookie-authentication-nodejs-nano/)
* article: [adding copy to nano](http://blog.jlank.com/2012/07/04/adding-copy-to-nano/)

@@ -555,0 +569,0 @@ ## roadmap

@@ -91,3 +91,3 @@ var path = require('path')

}
nk[method](npath, body).reply(status, response, headers);
nk.intercept(npath, method, body).reply(status, response, headers);
}

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