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

cdb-driver

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

cdb-driver - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

6

app/main.js

@@ -9,6 +9,6 @@ // const ChildProcess = require('child_process');

if(_isset(config,'object')) {
if(_isset(config.host,'string') && _isset(config.port,'number')) {
this.host = config.host + ':' + config.port;
if(_isset(config.host,'string')) {
this.host = config.host;
} else {
throw new TypeError('CDBDriver configuration is missing required keys!');
throw new TypeError('CDBDriver configuration is missing required key: host!');
}

@@ -15,0 +15,0 @@

@@ -1,1 +0,1 @@

"use strict";var _createClass=function(){function e(e,t){for(var s=0;s<t.length;s++){var r=t[s];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,s,r){return s&&e(t.prototype,s),r&&e(t,r),t}}();function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var _require=require("Base64"),btoa=_require.btoa,_isset=require("isset-helper"),CDBDriver=function(){function e(t){if(_classCallCheck(this,e),_isset(t,"object")){if(!_isset(t.host,"string")||!_isset(t.port,"number"))throw new TypeError("CDBDriver configuration is missing required keys!");this.host=t.host+":"+t.port,_isset(t.user,"string")&&_isset(t.pass,"string")?(this._auth=!0,this.user=t.user,this.pass=t.pass):this._auth=!1}else{if(!_isset(t,"string"))throw new TypeError("Invalid configuration passed to CDBDriver constructor!");try{if(t.includes("@")){this._auth=!0;var s=t.split("@"),r=s[0].split("//")[0]+"//",i=s[0].split("//")[1];this.user=i.split(":")[0],this.pass=i.split(":")[1],this.host=r+s[1].split(":")[0]+":"+parseInt(s[1].split(":")[1])}else this._auth=!1,this.host=t}catch(e){throw new TypeError("An error occurred while parsing CouchDB URL string.")}}this.host.endsWith("/")||(this.host=this.host+"/");try{new XMLHttpRequest,this._mode="xhr"}catch(e){throw this._mode="curl",new Error("CDBDriver currently not supports CURL mode!")}}return _createClass(e,[{key:"_getAuthHeader",value:function(){return"Basic "+btoa(this.user+":"+this.pass)}},{key:"_setAuthHeader",value:function(e){return e.setRequestHeader("Authorization",this._getAuthHeader())}},{key:"_buildCURL",value:function(e){var t="curl ";return _isset(e.method,"string")?t+="-X "+e.method+" ":t+="-X GET ",e.verbose&&(t+="-v "),_isset(e.data,"object")?(t+='-H "Content-Type: application/json" ',t+='-d "'+JSON.stringify(e.data)+'" '):_isset(e.data,"string")&&(t+='-d "'+e.data+'"'),this._auth&&(t+='-H "Authorization: '+this._getAuthHeader()+'" '),_isset(e.location,"string")?t+=this.host+e.location:t+=this.host,t}},{key:"_parseCURLResponse",value:function(e,t){var s,r;if(t){s={},r="",e.split("\n").forEach(function(e,t,i){if(e.startsWith("*"));else if(e.startsWith(">"));else if(e.startsWith("<")){e.replace("< ","");e.includes("HTTP/")&&(s.code=parseInt(e.replace(new RegExp("HTTP/[^s]+ "),"")))}else r+=e});try{s.body=JSON.parse(r)}catch(e){s.body=r}finally{return s}}else try{s=JSON.parse(e)}catch(t){return e}finally{return s}}},{key:"info",value:function(e){if("xhr"==this._mode){var t=new XMLHttpRequest;if(!_isset(e,"function"))return t.open("GET",this.host,!1),this._auth&&(t=this._setAuthHeader(t)),t.send(),{state:t.status,response:t.response};t.addEventListener("load",function(s){e({state:t.status,response:t.response})}),t.open("GET",this.host),this._auth&&(t=this._setAuthHeader(t)),t.send()}}},{key:"allDbs",value:function(e){if("xhr"==this._mode){var t=new XMLHttpRequest;if(!_isset(e,"function"))return t.open("GET",this.host+"_all_dbs",!1),this._auth&&(t=this._setAuthHeader(t)),t.send(),{state:t.status,response:t.response};t.addEventListener("load",function(s){e({state:t.status,response:t.response})}),t.open("GET",this.host+"_all_dbs"),this._auth&&(t=this._setAuthHeader(t)),t.send()}else _isset(e,"function")}},{key:"getDb",value:function(e,t){if(!_isset(e,"string"))throw new Error("CDBDriver.db() is missing required argument: dbIdentifier!");if("xhr"==this._mode){var s=new XMLHttpRequest;if(!_isset(t,"function"))return s.open("GET",this.host+e,!1),this._auth&&(s=this._setAuthHeader(s)),s.send(),{state:s.status,response:s.response};s.addEventListener("load",function(e){t({state:s.status,response:s.response})}),s.open("GET",this.host+e),this._auth&&(s=this._setAuthHeader(s)),s.send()}}},{key:"createDb",value:function(e,t){if(!_isset(e,"string"))throw new Error("CDBDriver.createDb() is missing required argument: dbIdentifier!");if("xhr"==this._mode){var s=new XMLHttpRequest;if(!_isset(t,"function"))return s.open("PUT",this.host+e,!1),this._auth&&(s=this._setAuthHeader(s)),s.send(),{state:s.status,response:s.response};s.addEventListener("load",function(e){t({state:s.status,response:s.response})}),s.open("PUT",this.host),this._auth&&(s=this._setAuthHeader(s)),s.send()}}},{key:"getDocs",value:function(e,t){if(!_isset(e,"string"))throw new Error("CDBDriver.getDocs() is missing required argument: dbIdentifier!");if("xhr"==this._mode){var s=new XMLHttpRequest;if(!_isset(t,"function"))return s.open("GET",this.host+e+"/_all_docs",!1),this._auth&&(s=this._setAuthHeader(s)),s.send(),{state:s.status,response:s.response};s.addEventListener("load",function(e){t({state:s.status,response:s.response})}),s.open("GET",this.host+e+"/_all_docs"),this._auth&&(s=this._setAuthHeader(s)),s.send()}}},{key:"storeDoc",value:function(e,t,s){if(!_isset(e,"string"))throw new Error("CDBDriver.storeDoc() is missing required argument: dbIdentifier!");if(!_isset(t,"object"))throw new Error("CDBDriver.storeDoc() is missing required argument: data!");if("xhr"==this._mode){var r=new XMLHttpRequest;if(!_isset(s,"function"))return r.open("POST",this.host+e,!1),this._auth&&(r=this._setAuthHeader(r)),r.setRequestHeader("Content-Type","application/json"),r.send(JSON.stringify(t)),{state:r.status,response:r.response};r.addEventListener("load",function(e){s({state:r.status,response:r.response})}),r.open("POST",this.host+e),this._auth&&(r=this._setAuthHeader(r)),r.setRequestHeader("Content-Type","application/json"),r.send(JSON.stringify(t))}}},{key:"getDoc",value:function(e,t,s){if(!_isset(e,"string"))throw new Error("CDBDriver.getDoc() is missing required argument: dbIdentifier!");if(!_isset(t,"string"))throw new Error("CDBDriver.getDoc() is missing required argument: docIdentifier!");if("xhr"==this._mode){var r=new XMLHttpRequest;if(!_isset(s,"function"))return r.open("GET",this.host+e+"/"+t,!1),this._auth&&(r=this._setAuthHeader(r)),r.send(),{state:r.status,response:r.response};r.addEventListener("load",function(e){s({state:r.status,response:r.response})}),r.open("GET",this.host+e+"/"+t),this._auth&&(r=this._setAuthHeader(r)),r.send()}}},{key:"deleteDoc",value:function(e,t,s,r){if(!_isset(e,"string"))throw new Error("CDBDriver.deleteDoc() is missing required argument: dbIdentifier!");if(!_isset(t,"string"))throw new Error("CDBDriver.deleteDoc() is missing required argument: docIdentifier!");if(!_isset(s,"string"))throw new Error("CDBDriver.deleteDoc() is missing required argument: docRevision!");if("xhr"==this._mode){var i=new XMLHttpRequest;if(!_isset(r,"function"))return i.open("DELETE",this.host+e+"/"+t+"?rev="+s,!1),this._auth&&(i=this._setAuthHeader(i)),i.send(),{state:i.status,response:i.response};i.addEventListener("load",function(e){r({state:i.status,response:i.response})}),i.open("DELETE",this.host+e+"/"+t+"?rev="+s),this._auth&&(i=this._setAuthHeader(i)),i.send()}}},{key:"updateDoc",value:function(e,t,s,r,i){if(!_isset(e,"string"))throw new Error("CDBDriver.updateDoc() is missing required argument: dbIdentifier!");if(!_isset(t,"string"))throw new Error("CDBDriver.updateDoc() is missing required argument: docIdentifier!");if(!_isset(s,"string"))throw new Error("CDBDriver.updateDoc() is missing required argument: docRevision!");if(!_isset(r,"object"))throw new Error("CDBDriver.updateDoc() is missing required argument: data!");if("xhr"==this._mode){var n=new XMLHttpRequest;if(!_isset(i,"function"))return n.open("PUT",this.host+e+"/"+t+"?rev="+s,!1),this._auth&&(n=this._setAuthHeader(n)),n.setRequestHeader("Content-Type","application/json"),n.send(JSON.stringify(r)),{state:n.status,resposne:n.response};n.addEventListener("load",function(e){i({state:n.status,response:n.response})}),n.open("PUT",this.host+e+"/"+t+"?rev="+s),this._auth&&(n=this._setAuthHeader(n)),n.setRequestHeader("Content-Type","application/json"),n.send(JSON.stringify(r))}}}]),e}();try{module.exports=CDBDriver}catch(e){}
"use strict";var _createClass=function(){function e(e,t){for(var s=0;s<t.length;s++){var i=t[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,s,i){return s&&e(t.prototype,s),i&&e(t,i),t}}();function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var _require=require("Base64"),btoa=_require.btoa,_isset=require("isset-helper"),CDBDriver=function(){function e(t){if(_classCallCheck(this,e),_isset(t,"object")){if(!_isset(t.host,"string"))throw new TypeError("CDBDriver configuration is missing required key: host!");this.host=t.host,_isset(t.user,"string")&&_isset(t.pass,"string")?(this._auth=!0,this.user=t.user,this.pass=t.pass):this._auth=!1}else{if(!_isset(t,"string"))throw new TypeError("Invalid configuration passed to CDBDriver constructor!");try{if(t.includes("@")){this._auth=!0;var s=t.split("@"),i=s[0].split("//")[0]+"//",r=s[0].split("//")[1];this.user=r.split(":")[0],this.pass=r.split(":")[1],this.host=i+s[1].split(":")[0]+":"+parseInt(s[1].split(":")[1])}else this._auth=!1,this.host=t}catch(e){throw new TypeError("An error occurred while parsing CouchDB URL string.")}}this.host.endsWith("/")||(this.host=this.host+"/");try{new XMLHttpRequest,this._mode="xhr"}catch(e){throw this._mode="curl",new Error("CDBDriver currently not supports CURL mode!")}}return _createClass(e,[{key:"_getAuthHeader",value:function(){return"Basic "+btoa(this.user+":"+this.pass)}},{key:"_setAuthHeader",value:function(e){return e.setRequestHeader("Authorization",this._getAuthHeader())}},{key:"_buildCURL",value:function(e){var t="curl ";return _isset(e.method,"string")?t+="-X "+e.method+" ":t+="-X GET ",e.verbose&&(t+="-v "),_isset(e.data,"object")?(t+='-H "Content-Type: application/json" ',t+='-d "'+JSON.stringify(e.data)+'" '):_isset(e.data,"string")&&(t+='-d "'+e.data+'"'),this._auth&&(t+='-H "Authorization: '+this._getAuthHeader()+'" '),_isset(e.location,"string")?t+=this.host+e.location:t+=this.host,t}},{key:"_parseCURLResponse",value:function(e,t){var s,i;if(t){s={},i="",e.split("\n").forEach(function(e,t,r){if(e.startsWith("*"));else if(e.startsWith(">"));else if(e.startsWith("<")){e.replace("< ","");e.includes("HTTP/")&&(s.code=parseInt(e.replace(new RegExp("HTTP/[^s]+ "),"")))}else i+=e});try{s.body=JSON.parse(i)}catch(e){s.body=i}finally{return s}}else try{s=JSON.parse(e)}catch(t){return e}finally{return s}}},{key:"info",value:function(e){if("xhr"==this._mode){var t=new XMLHttpRequest;if(!_isset(e,"function"))return t.open("GET",this.host,!1),this._auth&&(t=this._setAuthHeader(t)),t.send(),{state:t.status,response:t.response};t.addEventListener("load",function(s){e({state:t.status,response:t.response})}),t.open("GET",this.host),this._auth&&(t=this._setAuthHeader(t)),t.send()}}},{key:"allDbs",value:function(e){if("xhr"==this._mode){var t=new XMLHttpRequest;if(!_isset(e,"function"))return t.open("GET",this.host+"_all_dbs",!1),this._auth&&(t=this._setAuthHeader(t)),t.send(),{state:t.status,response:t.response};t.addEventListener("load",function(s){e({state:t.status,response:t.response})}),t.open("GET",this.host+"_all_dbs"),this._auth&&(t=this._setAuthHeader(t)),t.send()}else _isset(e,"function")}},{key:"getDb",value:function(e,t){if(!_isset(e,"string"))throw new Error("CDBDriver.db() is missing required argument: dbIdentifier!");if("xhr"==this._mode){var s=new XMLHttpRequest;if(!_isset(t,"function"))return s.open("GET",this.host+e,!1),this._auth&&(s=this._setAuthHeader(s)),s.send(),{state:s.status,response:s.response};s.addEventListener("load",function(e){t({state:s.status,response:s.response})}),s.open("GET",this.host+e),this._auth&&(s=this._setAuthHeader(s)),s.send()}}},{key:"createDb",value:function(e,t){if(!_isset(e,"string"))throw new Error("CDBDriver.createDb() is missing required argument: dbIdentifier!");if("xhr"==this._mode){var s=new XMLHttpRequest;if(!_isset(t,"function"))return s.open("PUT",this.host+e,!1),this._auth&&(s=this._setAuthHeader(s)),s.send(),{state:s.status,response:s.response};s.addEventListener("load",function(e){t({state:s.status,response:s.response})}),s.open("PUT",this.host),this._auth&&(s=this._setAuthHeader(s)),s.send()}}},{key:"getDocs",value:function(e,t){if(!_isset(e,"string"))throw new Error("CDBDriver.getDocs() is missing required argument: dbIdentifier!");if("xhr"==this._mode){var s=new XMLHttpRequest;if(!_isset(t,"function"))return s.open("GET",this.host+e+"/_all_docs",!1),this._auth&&(s=this._setAuthHeader(s)),s.send(),{state:s.status,response:s.response};s.addEventListener("load",function(e){t({state:s.status,response:s.response})}),s.open("GET",this.host+e+"/_all_docs"),this._auth&&(s=this._setAuthHeader(s)),s.send()}}},{key:"storeDoc",value:function(e,t,s){if(!_isset(e,"string"))throw new Error("CDBDriver.storeDoc() is missing required argument: dbIdentifier!");if(!_isset(t,"object"))throw new Error("CDBDriver.storeDoc() is missing required argument: data!");if("xhr"==this._mode){var i=new XMLHttpRequest;if(!_isset(s,"function"))return i.open("POST",this.host+e,!1),this._auth&&(i=this._setAuthHeader(i)),i.setRequestHeader("Content-Type","application/json"),i.send(JSON.stringify(t)),{state:i.status,response:i.response};i.addEventListener("load",function(e){s({state:i.status,response:i.response})}),i.open("POST",this.host+e),this._auth&&(i=this._setAuthHeader(i)),i.setRequestHeader("Content-Type","application/json"),i.send(JSON.stringify(t))}}},{key:"getDoc",value:function(e,t,s){if(!_isset(e,"string"))throw new Error("CDBDriver.getDoc() is missing required argument: dbIdentifier!");if(!_isset(t,"string"))throw new Error("CDBDriver.getDoc() is missing required argument: docIdentifier!");if("xhr"==this._mode){var i=new XMLHttpRequest;if(!_isset(s,"function"))return i.open("GET",this.host+e+"/"+t,!1),this._auth&&(i=this._setAuthHeader(i)),i.send(),{state:i.status,response:i.response};i.addEventListener("load",function(e){s({state:i.status,response:i.response})}),i.open("GET",this.host+e+"/"+t),this._auth&&(i=this._setAuthHeader(i)),i.send()}}},{key:"deleteDoc",value:function(e,t,s,i){if(!_isset(e,"string"))throw new Error("CDBDriver.deleteDoc() is missing required argument: dbIdentifier!");if(!_isset(t,"string"))throw new Error("CDBDriver.deleteDoc() is missing required argument: docIdentifier!");if(!_isset(s,"string"))throw new Error("CDBDriver.deleteDoc() is missing required argument: docRevision!");if("xhr"==this._mode){var r=new XMLHttpRequest;if(!_isset(i,"function"))return r.open("DELETE",this.host+e+"/"+t+"?rev="+s,!1),this._auth&&(r=this._setAuthHeader(r)),r.send(),{state:r.status,response:r.response};r.addEventListener("load",function(e){i({state:r.status,response:r.response})}),r.open("DELETE",this.host+e+"/"+t+"?rev="+s),this._auth&&(r=this._setAuthHeader(r)),r.send()}}},{key:"updateDoc",value:function(e,t,s,i,r){if(!_isset(e,"string"))throw new Error("CDBDriver.updateDoc() is missing required argument: dbIdentifier!");if(!_isset(t,"string"))throw new Error("CDBDriver.updateDoc() is missing required argument: docIdentifier!");if(!_isset(s,"string"))throw new Error("CDBDriver.updateDoc() is missing required argument: docRevision!");if(!_isset(i,"object"))throw new Error("CDBDriver.updateDoc() is missing required argument: data!");if("xhr"==this._mode){var n=new XMLHttpRequest;if(!_isset(r,"function"))return n.open("PUT",this.host+e+"/"+t+"?rev="+s,!1),this._auth&&(n=this._setAuthHeader(n)),n.setRequestHeader("Content-Type","application/json"),n.send(JSON.stringify(i)),{state:n.status,resposne:n.response};n.addEventListener("load",function(e){r({state:n.status,response:n.response})}),n.open("PUT",this.host+e+"/"+t+"?rev="+s),this._auth&&(n=this._setAuthHeader(n)),n.setRequestHeader("Content-Type","application/json"),n.send(JSON.stringify(i))}}}]),e}();try{module.exports=CDBDriver}catch(e){}
{
"name": "cdb-driver",
"version": "0.1.1",
"version": "0.1.2",
"description": "A driver library for connecting to a CouchDB instance through JavaScript.",

@@ -5,0 +5,0 @@ "main": "app/main.js",

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