Socket
Socket
Sign inDemoInstall

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.0.1 to 0.0.2

ROADMAP

13

error.js

@@ -13,4 +13,4 @@ /*

*/
function gen_err(error, code, http_code, type) {
if(typeof error === 'string') { error = new Error(error); }
function gen_err(reason,code,request,http_code,type) {
if(typeof reason === 'string') { error = new Error(reason); }
if(!type) {

@@ -20,9 +20,10 @@ type = http_code;

}
error.nano_code = code;
error.error = code;
error.http_code = http_code;
error.type = type;
error.namespace = type;
error.request = request;
return error;
}
exports.request_err = function (e,c,h) { return gen_err(e,c,h,"request"); };
exports.couch_err = function (e,c,h) { return gen_err(e,c,h,"couch"); };
exports.request_err = function (e,c,r,h) { return gen_err(e,c,r,h,"request"); };
exports.couch_err = function (e,c,r,h) { return gen_err(e,c,r,h,"couch"); };
/* Minimalistic Couch In Node */
var request = require('request')
, fs = require('fs')
, error = require('./error')

@@ -11,2 +12,5 @@ , headers = { "content-type": "application/json"

var public_functions = {};
if(typeof cfg === "string") {
cfg = require(cfg); // No CFG? Maybe it's a file path?
}

@@ -28,2 +32,5 @@ /*

function request_db(name,method,callback) {
if(!callback) { // Then ignore callback
callback = function () { return; };
}
var req =

@@ -38,3 +45,3 @@ { uri: cfg.database(name)

if(e) {
callback(error.request_err(e, "connect_db",status_code));
callback(error.request_err(e,"connect_db",req,status_code));
return;

@@ -45,3 +52,3 @@ }

else { // Proxy the error
callback(error.couch_err(parsed.reason,parsed.error,status_code));
callback(error.couch_err(parsed.reason,parsed.error,req,status_code));
}

@@ -54,9 +61,12 @@ });

*
* e.g. nano.db.create("test", {tried: 0, max_tries: 1},
* function (err) {
* if(err) { throw err; }
* // Do something
* console.log("yey! Dinosaurs! Rawr!");
* e.g. nano.db.create(db_name, function (e,b) {
* if(tried.tried === tried.max_retries) {
* callback("Retries work");
* return;
* }
* );
* else {
* tried.tried += 1;
* recursive_retries_create_db(tried,callback);
* }
* });
*

@@ -66,17 +76,59 @@ * @see request_db

function create_db(name, callback) {
request_db(name, "PUT", callback);
request_db(name,"PUT",callback);
}
/*
* Annihilates a CouchDB Database
*
* e.g. nano.db.delete(db_name);
*
* Even though this looks sync it is an async function
* and therefor order is not guaranteed
*
* @see request_db
*/
function destroy_db(name, callback) {
request_db(name, "DELETE", callback);
request_db(name,"DELETE",callback);
}
/*
* Gets information about a CouchDB Database
*
* e.g. nano.db.get(db_name, function(e,b) {
* console.log(b);
* });
*
* @see request_db
*/
function get_db(name, callback) {
request_db(name,"GET",callback);
}
/*
* Lists all the databases in CouchDB
*
* e.g. nano.db.get(db_name, function(e,b) {
* console.log(b);
* });
*
* @see request_db
*/
function list_dbs(callback) {
request_db("_all_dbs","GET",callback);
}
public_functions = { db: { create: create_db
//, get: get_db
, get: get_db
, destroy: destroy_db
, list: list_dbs
//, replicate: replicate_db
//, compact: compact_db
//, changes: { add: add_listener
// , remove: remove_listener}
}
//, doc: { create: create_doc
// , get: get_doc
// , destroy: destroy_doc
// }
//, create: create_doc
//, get: get_doc
//, destroy: destroy_doc
//, bulk: bulk_doc
//, list: list_docs
};

@@ -88,3 +140,3 @@

nano.version = JSON.parse(
require('fs').readFileSync(__dirname + "/package.json")).version;
fs.readFileSync(__dirname + "/package.json")).version;
nano.path = __dirname;
{ "name": "nano"
, "description": "NanoCouch is a minimalistic driver for CouchDB built on mikeals/request"
, "homepage": "http://github.com/dscape/nanocouch"
, "version": "0.0.1"
, "version": "0.0.2"
, "author": "Nuno Job <nunojobpinto@gmail.com> (http://nunojob.com)"

@@ -6,0 +6,0 @@ , "keywords": ["CouchDB", "data", "request", "json", "nosql", "micro", "nano"]

var vows = require('/usr/lib/node_modules/vows/lib/vows')
, assert = require('assert')
, cfg = require('../../cfg/tests.js')
, nano = require('../../nano')(cfg)
, db_name = "foo";
, nano = require('../../nano')(cfg);

@@ -11,6 +10,6 @@ /*****************************************************************************

function create_db (callback) {
nano.db.destroy(db_name, function () {
nano.db.create(db_name, function (e,b) {
nano.db.destroy("cr1", function () {
nano.db.create("cr1", function (e,b) {
callback(e,b);
return;
nano.db.destroy("cr1");
});

@@ -26,30 +25,10 @@ });

/*****************************************************************************
* create_db_recursive_error *
*****************************************************************************/
function create_db_recursive_error(callback) {
nano.db.destroy(db_name, function () {
nano.db.create(db_name, function (e,b) {
if(e) {
callback(e);
}
else {
create_db_recursive_error(name,callback);
}
});
});
}
function create_db_recursive_error_ok(e,tried) {
assert.equal(e.nano_code,"file_exists");
}
/*****************************************************************************
* recursive_retries_create_db *
*****************************************************************************/
function recursive_retries_create_db(tried,callback) {
nano.db.destroy(db_name, function () {
nano.db.create(db_name, function (e,b) {
nano.db.destroy("cr2", function () {
nano.db.create("cr2", function (e,b) {
if(tried.tried === tried.max_retries) {
callback(true);
return;
nano.db.destroy("cr2");
}

@@ -72,5 +51,2 @@ else {

, "=": create_db_ok },
"create_db_recursive_error": {
topic: function () { create_db_recursive_error(this.callback); }
, "=": create_db_recursive_error_ok },
"recursive_retries_create_db": {

@@ -77,0 +53,0 @@ topic: function () { recursive_retries_create_db({tried:0, max_retries:5},this.callback); }

@@ -6,6 +6,8 @@ var vows = require('/usr/lib/node_modules/vows/lib/vows')

function destroyDb (name,callback) {
nano.db.destroy(name, function (e,b) {
callback(e,b);
return;
function destroyDb (callback) {
nano.db.create("de1", function () {
nano.db.destroy("de1", function (e,b) {
callback(e,b);
return;
});
});

@@ -21,5 +23,5 @@ }

"nano.db.destroy(foo)": {
topic: function () { destroyDb("foo", this.callback); }
topic: function () { destroyDb(this.callback); }
, "=": destroyDbWorked
}
}).exportTo(module);
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