Comparing version 0.9.5 to 0.9.7
33
nano.js
@@ -62,3 +62,3 @@ /* minimal couch in node | ||
* relax * | ||
****************************************************************************/ | ||
***************************************************************************/ | ||
/* | ||
@@ -128,3 +128,3 @@ * relax | ||
if(!_.isEmpty(params)) { | ||
['startkey', 'endkey', 'key'].forEach(function (key) { | ||
['startkey', 'endkey', 'key', 'keys'].forEach(function (key) { | ||
if (key in params) { params[key] = JSON.stringify(params[key]); } | ||
@@ -141,7 +141,11 @@ }); | ||
} | ||
if(verbose) { console.log(req); } | ||
if(verbose) { console.log('>>'); console.log(req); } | ||
request(req, function(e,h,b){ | ||
if(verbose) { console.log('<<'); } | ||
rh = (h && h.headers || {}); | ||
rh['status-code'] = status_code = (h && h.statusCode || 500); | ||
if(e) { return callback(error.request(e,"socket",req,status_code),b,rh); } | ||
if(e) { | ||
if(verbose) { console.log({err: 'socket', body: b, headers: rh }); } | ||
return callback(error.request(e,"socket",req,status_code),b,rh); | ||
} | ||
delete rh.server; // prevent security vunerabilities related to couchdb | ||
@@ -154,7 +158,11 @@ delete rh['content-length']; // prevent problems with trims and stalled responses | ||
} | ||
if(verbose) { console.log({err: null, body: parsed, headers: rh}); } | ||
callback(null,parsed,rh); | ||
} | ||
else { // proxy the error directly from couchdb | ||
if(verbose) { console.log(parsed); } | ||
callback(error.couch(parsed.reason,parsed.error,req,status_code),parsed,rh); | ||
if(verbose) { | ||
console.log({err: 'couch', body: parsed, headers: rh}); | ||
} | ||
callback(error.couch(parsed.reason,parsed.error,req,status_code), | ||
parsed, rh); | ||
} | ||
@@ -164,7 +172,6 @@ }); | ||
if (callback) { | ||
if(verbose) { console.log({err: 'uncaught', body: exc}); } | ||
callback(error.uncaught(exc)); | ||
} | ||
else { | ||
console.error(exc); | ||
} | ||
else { console.error({err: 'uncaught', body: exc}); } | ||
} | ||
@@ -175,3 +182,3 @@ } | ||
* db * | ||
****************************************************************************/ | ||
***************************************************************************/ | ||
/* | ||
@@ -306,3 +313,3 @@ * creates a couchdb database | ||
* session * | ||
****************************************************************************/ | ||
***************************************************************************/ | ||
/* | ||
@@ -337,3 +344,3 @@ * creates session | ||
* doc * | ||
****************************************************************************/ | ||
***************************************************************************/ | ||
function document_module(db_name) { | ||
@@ -457,3 +464,3 @@ var public_functions = {}; | ||
* attachment * | ||
**************************************************************************/ | ||
*************************************************************************/ | ||
/* | ||
@@ -460,0 +467,0 @@ * inserting an attachment |
@@ -5,3 +5,3 @@ { "name" : "nano" | ||
, "repository" : "git://github.com/dscape/nano" | ||
, "version" : "0.9.5" | ||
, "version" : "0.9.7" | ||
, "author" : "Nuno Job <nunojobpinto@gmail.com> (http://nunojob.com)" | ||
@@ -13,2 +13,3 @@ , "contributors" : | ||
, "Artur Konarski (http://tarantoga.com)" | ||
, "Pedro Teixeira <pedro.teixeira@gmail.com (http://metaduck.com)" | ||
] | ||
@@ -15,0 +16,0 @@ , "keywords" : ["couchdb", "data", "request", "json", "nosql", "micro", "nano"] |
@@ -28,7 +28,7 @@ # nano | ||
// clean up the database we created previously | ||
nano.db.destroy("alice", function(err,response,headers) { | ||
nano.db.destroy("alice", function() { | ||
nano.db.create("alice", function() { | ||
// specify the database we are going to use | ||
var alice = nano.use("alice"); | ||
alice.insert({crazy: true}, "rabbit", function(e,r,h){ | ||
alice.insert({crazy: true}, "rabbit", function(e,b,h){ | ||
if(e) { throw e; } | ||
@@ -47,6 +47,6 @@ console.log("you have inserted the rabbit.") | ||
in `nano` a callback has always three arguments | ||
in `nano` *a callback has always the same three arguments* | ||
``` js | ||
// 6: alice.insert({crazy: true}, "rabbit", function(e,r,h) { | ||
// 6: alice.insert({crazy: true}, "rabbit", function(e,b,h) { | ||
// 7: if(e) { throw e; } | ||
@@ -59,7 +59,7 @@ // 8: console.log("you have inserted the rabbit.") | ||
e: the `error`, if any. check error.js for more info. | ||
r: the http `response body` from couchdb, if no error. | ||
h: the http response `headers` from couchdb, if no error. | ||
e: the `error`, if any | ||
b: the http `response body` from couchdb, if no error. json parsed body, binary for non-json responses | ||
h: the http response `headers` from couchdb, if no error | ||
errors include responses from couchdb which had a non-200 response code. that's it. don't forget to delete the database you created: | ||
errors include responses from couchdb which had a non 200 response code. that's it. don't forget to delete the database you created: | ||
@@ -94,2 +94,4 @@ ``` js | ||
`server.config` | ||
`server.session.create` | ||
`server.session.destroy` | ||
@@ -96,0 +98,0 @@ ### aliases |
var ensure = require('ensure') | ||
, cfg = require('../../cfg/tests.js') | ||
, nano = require('../../nano')(cfg) | ||
, tests = exports; | ||
, db_name = require('../utils').db_name("att_de") | ||
, tests = exports | ||
; | ||
function db_name(i) { return "att_de" + i; } | ||
function db(i) { return nano.use(db_name(i)); } | ||
@@ -8,0 +9,0 @@ |
var ensure = require('ensure') | ||
, cfg = require('../../cfg/tests.js') | ||
, nano = require('../../nano')(cfg) | ||
, db_name = require('../utils').db_name("att_ge") | ||
, tests = exports | ||
, pixel = "Qk06AAAAAAAAADYAAAAoAAAAAQAAAP////8BABgAAAAAAAAAAAATCwAAEwsAAAAAAAAAAAAAWm2CAA=="; | ||
, pixel = "Qk06AAAAAAAAADYAAAAoAAAAAQAAAP////8BABgAAAAAAAAAAAATCwAAEwsAAAAAAAAAAAAAWm2CAA==" | ||
; | ||
function db_name(i) { return "att_ge" + i; } | ||
function db(i) { return nano.use(db_name(i)); } | ||
@@ -9,0 +10,0 @@ |
var ensure = require('ensure') | ||
, cfg = require('../../cfg/tests.js') | ||
, nano = require('../../nano')(cfg) | ||
, tests = exports; | ||
, db_name = require('../utils').db_name("att_in") | ||
, tests = exports | ||
; | ||
function db_name(i) { return "att_in" + i; } | ||
function db(i) { return nano.use(db_name(i)); } | ||
@@ -8,0 +9,0 @@ |
@@ -6,5 +6,5 @@ var ensure = require('ensure') | ||
, tests = exports | ||
, db_name = require('../utils').db_name("att_pi") | ||
, pixel = "Qk06AAAAAAAAADYAAAAoAAAAAQAAAP////8BABgAAAAAAAAAAAATCwAAEwsAAAAAAAAAAAAAWm2CAA=="; | ||
function db_name(i) { return "att_pi" + i; } | ||
function db(i) { return nano.use(db_name(i)); } | ||
@@ -11,0 +11,0 @@ function file_name(i) { return __dirname + "/." + i + "-tmp.bmp"; } |
var ensure = require('ensure') | ||
, cfg = require('../../cfg/tests.js') | ||
, nano = require('../../nano')(cfg) | ||
, tests = exports; | ||
, db_name = require('../utils').db_name("att_up") | ||
, tests = exports | ||
; | ||
function db_name(i) { return "att_up" + i; } | ||
function db(i) { return nano.use(db_name(i)); } | ||
@@ -8,0 +9,0 @@ |
@@ -5,5 +5,6 @@ var ensure = require('ensure') | ||
, nano = require('../../nano')(cfg) | ||
, tests = exports; | ||
, db_name = require('../utils').db_name("doc_ch") | ||
, tests = exports | ||
; | ||
function db_name(i) { return "doc_ch" + i; } | ||
function db(i) { return nano.use(db_name(i)); } | ||
@@ -10,0 +11,0 @@ |
@@ -1,19 +0,22 @@ | ||
var ensure = require('ensure') | ||
, async = require('async') | ||
, cfg = require('../../cfg/tests.js') | ||
, nano = require('../../nano')(cfg) | ||
, tests = exports; | ||
var ensure = require('ensure') | ||
, async = require('async') | ||
, cfg = require('../../cfg/tests.js') | ||
, nano = require('../../nano')(cfg) | ||
, db_name = require('../utils').db_name("db_co") | ||
, tests = exports | ||
; | ||
function db(i) { return nano.use(db_name(i)); } | ||
tests.compact_db = function (callback) { | ||
nano.db.create("db_co1", function () { | ||
var db = nano.use("db_co1"); | ||
nano.db.create(db_name('1'), function () { | ||
async.parallel( | ||
[ function(cb) { db.insert({"foo": "bar"},"foobar",cb); } | ||
, function(cb) { db.insert({"bar": "foo"},"barfoo",cb); } | ||
, function(cb) { db.insert({"foo": "baz"},"foobaz", | ||
function (e,b) { db.destroy("foobaz", b._rev, cb); }); } | ||
[ function(cb) { db('1').insert({"foo": "bar"},"foobar",cb); } | ||
, function(cb) { db('1').insert({"bar": "foo"},"barfoo",cb); } | ||
, function(cb) { db('1').insert({"foo": "baz"},"foobaz", | ||
function (e,b) { db('1').destroy("foobaz", b._rev, cb); }); } | ||
], | ||
function(err, results){ | ||
db.compact(function () { | ||
db.info(callback); | ||
db('1').compact(function () { | ||
db('1').info(callback); | ||
}); | ||
@@ -25,3 +28,3 @@ }); | ||
tests.compact_db_ok = function (err,list) { | ||
nano.db.destroy("db_co1"); | ||
nano.db.destroy(db_name('1')); | ||
this.t.notOk(err); | ||
@@ -28,0 +31,0 @@ this.t.equal(list.doc_count, 3); |
var ensure = require('ensure') | ||
, cfg = require('../../cfg/tests.js') | ||
, nano = require('../../nano')(cfg) | ||
, db_name = require('../utils').db_name("db_cr") | ||
, tests = exports; | ||
tests.create_db = function (callback) { | ||
nano.db.destroy("db_cr1", function () { | ||
nano.db.create("db_cr1", callback); | ||
nano.db.destroy(db_name('1'), function () { | ||
nano.db.create(db_name('1'), callback); | ||
}); | ||
@@ -13,3 +14,3 @@ }; | ||
tests.create_db_ok = function (e,b) { | ||
nano.db.destroy("db_cr1"); | ||
nano.db.destroy(db_name('1')); | ||
this.t.notOk(e); | ||
@@ -16,0 +17,0 @@ this.t.equal(b.ok, true); |
var ensure = require('ensure') | ||
, cfg = require('../../cfg/tests.js') | ||
, nano = require('../../nano')(cfg) | ||
, db_name = require('../utils').db_name("db_de") | ||
, tests = exports; | ||
tests.destroy_db = function (callback) { | ||
nano.db.create("db_de1", function () { | ||
nano.db.destroy("db_de1", callback); | ||
nano.db.create(db_name('1'), function () { | ||
nano.db.destroy(db_name('1'), callback); | ||
}); | ||
@@ -10,0 +11,0 @@ }; |
var ensure = require('ensure') | ||
, cfg = require('../../cfg/tests.js') | ||
, nano = require('../../nano')(cfg) | ||
, db_name = require('../utils').db_name("db_ge") | ||
, tests = exports; | ||
tests.get_db = function (callback) { | ||
nano.db.create("db_ge1", function () { | ||
nano.db.get("db_ge1", function (e,b) { | ||
nano.db.create(db_name('1'), function () { | ||
nano.db.get(db_name('1'), function (e,b) { | ||
callback(e,b); | ||
@@ -16,9 +17,9 @@ return; | ||
tests.get_db_ok = function (e,b) { | ||
nano.db.destroy("db_ge1"); | ||
nano.db.destroy(db_name('1')); | ||
this.t.notOk(e); | ||
this.t.equal(b.doc_count,0); | ||
this.t.equal(b.doc_del_count,0); | ||
this.t.equal(b.db_name,"db_ge1"); | ||
this.t.equal(b.db_name,db_name('1')); | ||
}; | ||
ensure(__filename,tests,module,process.argv[2]); |
var ensure = require('ensure') | ||
, cfg = require('../../cfg/tests.js') | ||
, nano = require('../../nano')(cfg) | ||
, db_name = require('../utils').db_name("db_li") | ||
, tests = exports; | ||
tests.list_db = function (callback) { | ||
nano.db.create("db_li1", function () { | ||
nano.db.create(db_name('1'), function () { | ||
nano.db.list(callback); | ||
@@ -13,7 +14,7 @@ }); | ||
tests.list_db_ok = function (e,b) { | ||
nano.db.destroy("db_li1"); | ||
nano.db.destroy(db_name('1')); | ||
this.t.notOk(e); | ||
this.t.notEqual(b.indexOf("db_li1"),-1); | ||
this.t.notEqual(b.indexOf(db_name('1')),-1); | ||
}; | ||
ensure(__filename,tests,module,process.argv[2]); |
@@ -5,8 +5,9 @@ var ensure = require('ensure') | ||
, nano = require('../../nano')(cfg) | ||
, db_name = require('../utils').db_name("db_re") | ||
, tests = exports; | ||
tests.replicate_db = function (callback) { | ||
nano.db.create("db_re1", function () { | ||
var db = nano.use("db_re1") | ||
, replica = nano.use("db_re1_replica"); | ||
nano.db.create(db_name('1'), function () { | ||
var db = nano.use(db_name('1')) | ||
, replica = nano.use(db_name('1')+"_replica"); | ||
async.parallel( | ||
@@ -16,6 +17,6 @@ [ function(cb) { db.insert({"foo": "bar"},"foobar",cb); } | ||
, function(cb) { db.insert({"foo": "baz"},"foobaz",cb); } | ||
, function(cb) { nano.db.create("db_re1_replica", cb); } | ||
, function(cb) { nano.db.create(db_name('1')+"_replica", cb); } | ||
], | ||
function(err, results) { | ||
db.replicate("db_re1_replica", function() { | ||
db.replicate(db_name('1')+"_replica", function() { | ||
replica.list(callback); | ||
@@ -28,4 +29,4 @@ }); | ||
tests.replicate_db_ok = function (e,b) { | ||
nano.db.destroy("db_re1"); | ||
nano.db.destroy("db_re1_replica"); | ||
nano.db.destroy(db_name('1')); | ||
nano.db.destroy(db_name('1')+"_replica"); | ||
this.t.notOk(e); | ||
@@ -32,0 +33,0 @@ this.t.equal(b.total_rows, 3); |
@@ -5,5 +5,5 @@ var ensure = require('ensure') | ||
, nano = require('../../nano')(cfg) | ||
, db_name = require('../utils').db_name("doc_bu") | ||
, tests = exports; | ||
function db_name(i) { return "doc_bu" + i; } | ||
function db(i) { return nano.use(db_name(i)); } | ||
@@ -10,0 +10,0 @@ |
var ensure = require('ensure') | ||
, cfg = require('../../cfg/tests.js') | ||
, nano = require('../../nano')(cfg) | ||
, db_name = require('../utils').db_name("doc_de") | ||
, tests = exports; | ||
tests.destroy_doc = function (callback) { | ||
var db = nano.use("doc_de1"); | ||
nano.db.create("doc_de1", function () { | ||
var db = nano.use(db_name('1')); | ||
nano.db.create(db_name('1'), function () { | ||
db.insert({foo: "bar"}, "foo", function (_,b) { | ||
@@ -19,3 +20,3 @@ db.destroy("foo", b.rev, function (e,b) { | ||
tests.destroy_doc_ok = function (e,b) { | ||
nano.db.destroy("doc_de1"); | ||
nano.db.destroy(db_name('1')); | ||
this.t.notOk(e); | ||
@@ -22,0 +23,0 @@ this.t.ok(b.ok); |
var ensure = require('ensure') | ||
, cfg = require('../../cfg/tests.js') | ||
, nano = require('../../nano')(cfg) | ||
, db_name = require('../utils').db_name("doc_ge") | ||
, tests = exports; | ||
function db_name(i) { return "doc_ge" + i; } | ||
function db(i) { return nano.use(db_name(i)); } | ||
@@ -8,0 +8,0 @@ |
var ensure = require('ensure') | ||
, cfg = require('../../cfg/tests.js') | ||
, nano = require('../../nano')(cfg) | ||
, tests = exports; | ||
, db_name = require('../utils').db_name("doc_in") | ||
, tests = exports | ||
; | ||
function db_name(i) { return "doc_in" + i; } | ||
function db(i) { return nano.use(db_name(i)); } | ||
@@ -27,3 +28,3 @@ | ||
}); | ||
} | ||
}; | ||
@@ -36,4 +37,4 @@ tests.insert_doc_path_ok = function (e,b) { | ||
this.t.equal(b.id, "some/path"); | ||
} | ||
}; | ||
ensure(__filename,tests,module,process.argv[2]); |
@@ -5,5 +5,6 @@ var ensure = require('ensure') | ||
, nano = require('../../nano')(cfg) | ||
, tests = exports; | ||
, db_name = require('../utils').db_name("doc_li") | ||
, tests = exports | ||
; | ||
function db_name(i) { return "doc_li" + i; } | ||
function db(i) { return nano.use(db_name(i)); } | ||
@@ -10,0 +11,0 @@ |
var ensure = require('ensure') | ||
, cfg = require('../../cfg/tests.js') | ||
, nano = require('../../nano')(cfg) | ||
, db_name = require('../utils').db_name("doc_up") | ||
, tests = exports; | ||
function db_name(i) { return "doc_up" + i; } | ||
function db(i) { return nano.use(db_name(i)); } | ||
@@ -8,0 +8,0 @@ |
@@ -5,7 +5,8 @@ var ensure = require('ensure') | ||
, nano = require('../../nano')(cfg) | ||
, db_name = require('../utils').db_name("view_co") | ||
, tests = exports; | ||
tests.compact_view = function (callback) { | ||
nano.db.create("view_co1", function () { | ||
var db = nano.use("view_co1"); | ||
nano.db.create(db_name('1'), function () { | ||
var db = nano.use(db_name('1')); | ||
async.parallel( | ||
@@ -32,3 +33,3 @@ [ function(cb) { db.insert({"foo": "bar"},"foobar",cb); } | ||
tests.compact_view_ok = function (err,view) { | ||
nano.db.destroy("view_co1"); | ||
nano.db.destroy(db_name('1')); | ||
this.t.notOk(err); | ||
@@ -35,0 +36,0 @@ this.t.equal(view.total_rows, 2); |
@@ -5,7 +5,9 @@ var ensure = require('ensure') | ||
, nano = require('../../nano')(cfg) | ||
, tests = exports; | ||
, db_name = require('../utils').db_name("view_md") | ||
, tests = exports | ||
; | ||
tests.multi_doc = function (callback) { | ||
nano.db.create("view_md1", function () { | ||
var db = nano.use("view_md1"); | ||
nano.db.create(db_name('1'), function () { | ||
var db = nano.use(db_name('1')); | ||
async.parallel( | ||
@@ -29,3 +31,3 @@ [ function(cb) { db.insert({"foo": "bar"},"foo",cb); } | ||
tests.multi_doc_ok = function (err,view) { | ||
nano.db.destroy("view_md1"); | ||
nano.db.destroy(db_name('1')); | ||
this.t.notOk(err); | ||
@@ -32,0 +34,0 @@ this.t.equal(view.rows.length, 2); |
@@ -5,5 +5,5 @@ var ensure = require('ensure') | ||
, nano = require('../../nano')(cfg) | ||
, db_name = require('../utils').db_name("view_qu") | ||
, tests = exports; | ||
function db_name(i) { return "view_qu" + i; } | ||
function db_gen(i) { return nano.use(db_name(i)); } | ||
@@ -76,14 +76,2 @@ | ||
// Derek please fix me :) | ||
// | ||
//tests.naive_grouping = function (cb) { | ||
// complex_key_test(cb,"3",{ startkey: ["San Francisco // CA, USA",''], endkey: ["San Francisco // CA, USA",'~~']}); | ||
//}; | ||
// | ||
//tests.naive_grouping_ok = function (e,b,h) { | ||
// nano.db.destroy(db_name('3')); | ||
// this.t.notOk(e); | ||
// this.t.equal(b,1); | ||
//}; | ||
ensure(__filename, tests, module, process.argv[2]); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59543
38
1425
211