cdb-driver
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -55,3 +55,3 @@ // const ChildProcess = require('child_process'); | ||
var res = this.info(); | ||
var res = this.info().response; | ||
if(parseInt(res.version) < 2) { | ||
@@ -58,0 +58,0 @@ // throw new Error('Invalid CouchDB Version! Required version >= 2, found '+res.version+'.'); |
@@ -1,1 +0,1 @@ | ||
"use strict";var _createClass=function(){function e(e,s){for(var t=0;t<s.length;t++){var r=s[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(s,t,r){return t&&e(s.prototype,t),r&&e(s,r),s}}();function _classCallCheck(e,s){if(!(e instanceof s))throw new TypeError("Cannot call a class as a function")}var btoa=require("btoa"),_isset=require("isset-helper"),CDBDriver=function(){function e(s){if(_classCallCheck(this,e),_isset(s,"object")){if(!_isset(s.host,"string"))throw new TypeError("CDBDriver configuration is missing required key: host!");this.host=s.host,_isset(s.user,"string")&&_isset(s.pass,"string")?(this._auth=!0,this.user=s.user,this.pass=s.pass):this._auth=!1}else{if(!_isset(s,"string"))throw new TypeError("Invalid configuration passed to CDBDriver constructor!");try{if(s.includes("@")){this._auth=!0;var t=s.split("@"),r=t[0].split("//")[0]+"//",i=t[0].split("//")[1];this.user=i.split(":")[0],this.pass=i.split(":")[1],this.host=r+t[1].split(":")[0]+":"+parseInt(t[1].split(":")[1])}else this._auth=!1,this.host=s}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!")}var n=this.info();parseInt(n.version)<2?this.legacy=!0:this.legacy=!1}return _createClass(e,[{key:"_getAuthHeader",value:function(){return"Basic "+btoa(this.user+":"+this.pass)}},{key:"_setAuthHeader",value:function(e){e.setRequestHeader("Authorization",this._getAuthHeader())}},{key:"_buildCURL",value:function(e){var s="curl ";return _isset(e.method,"string")?s+="-X "+e.method+" ":s+="-X GET ",e.verbose&&(s+="-v "),_isset(e.data,"object")?(s+='-H "Content-Type: application/json" ',s+='-d "'+JSON.stringify(e.data)+'" '):_isset(e.data,"string")&&(s+='-d "'+e.data+'"'),this._auth&&(s+='-H "Authorization: '+this._getAuthHeader()+'" '),_isset(e.location,"string")?s+=this.host+e.location:s+=this.host,s}},{key:"_parseCURLResponse",value:function(e,s){var t,r;if(s){t={},r="",e.split("\n").forEach(function(e,s,i){if(e.startsWith("*"));else if(e.startsWith(">"));else if(e.startsWith("<")){e.replace("< ","");e.includes("HTTP/")&&(t.code=parseInt(e.replace(new RegExp("HTTP/[^s]+ "),"")))}else r+=e});try{t.body=JSON.parse(r)}catch(e){t.body=r}finally{return t}}else try{t=JSON.parse(e)}catch(s){return e}finally{return t}}},{key:"info",value:function(e){if("xhr"==this._mode){var s=new XMLHttpRequest;if(!_isset(e,"function")){s.open("GET",this.host,!1),this._auth&&this._setAuthHeader(s),s.send();try{var t=JSON.parse(s.response)}catch(e){t=s.response}return{state:s.status,response:t}}s.addEventListener("load",function(t){try{var r=JSON.parse(s.response)}catch(e){r=s.response}e({state:s.status,response:r})}),s.open("GET",this.host),this._auth&&this._setAuthHeader(s),s.send()}}},{key:"allDbs",value:function(e){if("xhr"==this._mode){var s=new XMLHttpRequest;if(!_isset(e,"function")){s.open("GET",this.host+"_all_dbs",!1),this._auth&&this._setAuthHeader(s),s.send();try{var t=JSON.parse(s.response)}catch(e){t=s.response}return{state:s.status,response:t}}s.addEventListener("load",function(t){try{var r=JSON.parse(s.response)}catch(e){r=s.response}e({state:s.status,response:r})}),s.open("GET",this.host+"_all_dbs"),this._auth&&this._setAuthHeader(s),s.send()}else _isset(e,"function")}},{key:"getDb",value:function(e,s){if(!_isset(e,"string"))throw new Error("CDBDriver.db() is missing required argument: dbIdentifier!");if("xhr"==this._mode){var t=new XMLHttpRequest;if(!_isset(s,"function")){t.open("GET",this.host+e,!1),this._auth&&this._setAuthHeader(t),t.send();try{var r=JSON.parse(t.response)}catch(e){r=t.response}return{state:t.status,response:r}}t.addEventListener("load",function(e){try{var r=JSON.parse(t.response)}catch(e){r=t.response}s({state:t.status,response:r})}),t.open("GET",this.host+e),this._auth&&this._setAuthHeader(t),t.send()}}},{key:"createDb",value:function(e,s){if(!_isset(e,"string"))throw new Error("CDBDriver.createDb() is missing required argument: dbIdentifier!");if("xhr"==this._mode){var t=new XMLHttpRequest;if(!_isset(s,"function")){t.open("PUT",this.host+e,!1),this._auth&&this._setAuthHeader(t),t.send();try{var r=JSON.parse(t.response)}catch(e){r=t.response}return{state:t.status,response:r}}t.addEventListener("load",function(e){try{var r=JSON.parse(t.response)}catch(e){r=t.response}s({state:t.status,response:r})}),t.open("PUT",this.host),this._auth&&this._setAuthHeader(t),t.send()}}},{key:"getDocs",value:function(e,s){if(!_isset(e,"string"))throw new Error("CDBDriver.getDocs() is missing required argument: dbIdentifier!");if("xhr"==this._mode){var t=new XMLHttpRequest;if(!_isset(s,"function")){t.open("GET",this.host+e+"/_all_docs",!1),this._auth&&this._setAuthHeader(t),t.send();try{var r=JSON.parse(t.response)}catch(e){r=t.response}return{state:t.status,response:r}}t.addEventListener("load",function(e){try{var r=JSON.parse(t.response)}catch(e){r=t.response}s({state:t.status,response:r})}),t.open("GET",this.host+e+"/_all_docs"),this._auth&&this._setAuthHeader(t),t.send()}}},{key:"storeDoc",value:function(e,s,t){if(!_isset(e,"string"))throw new Error("CDBDriver.storeDoc() is missing required argument: dbIdentifier!");if(!_isset(s,"object"))throw new Error("CDBDriver.storeDoc() is missing required argument: data!");if("xhr"==this._mode){var r=new XMLHttpRequest;if(!_isset(t,"function")){r.open("POST",this.host+e,!1),this._auth&&this._setAuthHeader(r),r.setRequestHeader("Content-Type","application/json"),r.send(JSON.stringify(s));try{var i=JSON.parse(r.response)}catch(e){i=r.response}return{state:r.status,response:i}}r.addEventListener("load",function(e){try{var s=JSON.parse(r.response)}catch(e){s=r.response}t({state:r.status,response:s})}),r.open("POST",this.host+e),this._auth&&this._setAuthHeader(r),r.setRequestHeader("Content-Type","application/json"),r.send(JSON.stringify(s))}}},{key:"getDoc",value:function(e,s,t){if(!_isset(e,"string"))throw new Error("CDBDriver.getDoc() is missing required argument: dbIdentifier!");if(!_isset(s,"string"))throw new Error("CDBDriver.getDoc() is missing required argument: docIdentifier!");if("xhr"==this._mode){var r=new XMLHttpRequest;if(!_isset(t,"function")){r.open("GET",this.host+e+"/"+s,!1),this._auth&&this._setAuthHeader(r),r.send();try{var i=JSON.parse(r.response)}catch(e){i=r.response}return{state:r.status,response:i}}r.addEventListener("load",function(e){try{var s=JSON.parse(r.response)}catch(e){s=r.response}t({state:r.status,response:s})}),r.open("GET",this.host+e+"/"+s),this._auth&&this._setAuthHeader(r),r.send()}}},{key:"deleteDoc",value:function(e,s,t,r){if(!_isset(e,"string"))throw new Error("CDBDriver.deleteDoc() is missing required argument: dbIdentifier!");if(!_isset(s,"string"))throw new Error("CDBDriver.deleteDoc() is missing required argument: docIdentifier!");if(!_isset(t,"string"))throw new Error("CDBDriver.deleteDoc() is missing required argument: docRevision!");if("xhr"==this._mode){var i=new XMLHttpRequest;if(!_isset(r,"function")){i.open("DELETE",this.host+e+"/"+s+"?rev="+t,!1),this._auth&&this._setAuthHeader(i),i.send();try{var n=JSON.parse(i.response)}catch(e){n=i.response}return{state:i.status,response:n}}i.addEventListener("load",function(e){try{var s=JSON.parse(i.response)}catch(e){s=i.response}r({state:i.status,response:s})}),i.open("DELETE",this.host+e+"/"+s+"?rev="+t),this._auth&&this._setAuthHeader(i),i.send()}}},{key:"updateDoc",value:function(e,s,t,r,i){if(!_isset(e,"string"))throw new Error("CDBDriver.updateDoc() is missing required argument: dbIdentifier!");if(!_isset(s,"string"))throw new Error("CDBDriver.updateDoc() is missing required argument: docIdentifier!");if(!_isset(t,"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")){n.open("PUT",this.host+e+"/"+s+"?rev="+t,!1),this._auth&&this._setAuthHeader(n),n.setRequestHeader("Content-Type","application/json"),n.send(JSON.stringify(r));try{var a=JSON.parse(n.response)}catch(e){a=n.response}return{state:n.status,response:a}}n.addEventListener("load",function(e){try{var s=JSON.parse(n.response)}catch(e){s=n.response}i({state:n.status,response:s})}),n.open("PUT",this.host+e+"/"+s+"?rev="+t),this._auth&&this._setAuthHeader(n),n.setRequestHeader("Content-Type","application/json"),n.send(JSON.stringify(r))}}},{key:"storeUser",value:function(e,s){if(!_isset(e.username,"string"))throw new Error("CDBDriver.storeUser() is missing required argument: username!");if(!_isset(e.password,"string"))throw new Error("CDBDriver.storeUser() is missing required argument: password!");var t={_id:"org.couchdb.user:"+e.username,name:e.username,roles:_isset(e.roles,"object")?e.roles:[],type:"user",password:e.password};if(_isset(e.additionals,"object"))for(var r in e.additionals)e.additionals.hasOwnProperty(r)&&!t.hasOwnProperty(r)&&(t[r]=e.additionals[r]);if("xhr"==this._mode){var i=new XMLHttpRequest;if(!_isset(s,"function")){i.open("PUT",this.host+"_users/"+t._id,!1),this._auth&&this._setAuthHeader(i),i.setRequestHeader("Content-Type","application/json"),i.send(JSON.stringify(t));try{var n=JSON.parse(i.response)}catch(e){n=i.response}return{state:i.status,response:n}}i.addEventListener("load",function(e){try{var t=JSON.parse(i.response)}catch(e){t=i.response}s({state:i.status,response:t})}),i.open("PUT",this.host+"_users/"+t._id),this._auth&&this._setAuthHeader(i),i.setRequestHeader("Content-Type","application/json"),i.send(JSON.stringify(t))}}},{key:"storeAdmin",value:function(e,s,t){if(!_isset(e,"string"))throw new Error("CDBDriver.storeUser() is missing required argument: username!");if(!_isset(s,"string"))throw new Error("CDBDriver.storeUser() is missing required argument: password!");if(this.legacy)var r=this.host+"_config/admins/"+e;else r=this.host+"_node/_local/_config/admins/"+e;if("xhr"==this._mode){var i=new XMLHttpRequest;if(!_isset(t,"function")){i.open("PUT",r,!1),this._auth&&this._setAuthHeader(i),i.setRequestHeader("Content-Type","application/json"),i.send('"'+s+'"');try{var n=JSON.parse(i.response)}catch(e){n=i.response}return{state:i.status,response:n}}i.addEventListener("load",function(e){try{var s=JSON.parse(i.response)}catch(e){s=i.response}t({state:i.status,response:s})}),i.open("PUT",r),this._auth&&this._setAuthHeader(i),i.setRequestHeader("Content-Type","application/json"),i.send('"'+s+'"')}}}]),e}();try{module.exports=CDBDriver}catch(e){} | ||
"use strict";var _createClass=function(){function e(e,s){for(var t=0;t<s.length;t++){var r=s[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(s,t,r){return t&&e(s.prototype,t),r&&e(s,r),s}}();function _classCallCheck(e,s){if(!(e instanceof s))throw new TypeError("Cannot call a class as a function")}var btoa=require("btoa"),_isset=require("isset-helper"),CDBDriver=function(){function e(s){if(_classCallCheck(this,e),_isset(s,"object")){if(!_isset(s.host,"string"))throw new TypeError("CDBDriver configuration is missing required key: host!");this.host=s.host,_isset(s.user,"string")&&_isset(s.pass,"string")?(this._auth=!0,this.user=s.user,this.pass=s.pass):this._auth=!1}else{if(!_isset(s,"string"))throw new TypeError("Invalid configuration passed to CDBDriver constructor!");try{if(s.includes("@")){this._auth=!0;var t=s.split("@"),r=t[0].split("//")[0]+"//",i=t[0].split("//")[1];this.user=i.split(":")[0],this.pass=i.split(":")[1],this.host=r+t[1].split(":")[0]+":"+parseInt(t[1].split(":")[1])}else this._auth=!1,this.host=s}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!")}var n=this.info().response;parseInt(n.version)<2?this.legacy=!0:this.legacy=!1}return _createClass(e,[{key:"_getAuthHeader",value:function(){return"Basic "+btoa(this.user+":"+this.pass)}},{key:"_setAuthHeader",value:function(e){e.setRequestHeader("Authorization",this._getAuthHeader())}},{key:"_buildCURL",value:function(e){var s="curl ";return _isset(e.method,"string")?s+="-X "+e.method+" ":s+="-X GET ",e.verbose&&(s+="-v "),_isset(e.data,"object")?(s+='-H "Content-Type: application/json" ',s+='-d "'+JSON.stringify(e.data)+'" '):_isset(e.data,"string")&&(s+='-d "'+e.data+'"'),this._auth&&(s+='-H "Authorization: '+this._getAuthHeader()+'" '),_isset(e.location,"string")?s+=this.host+e.location:s+=this.host,s}},{key:"_parseCURLResponse",value:function(e,s){var t,r;if(s){t={},r="",e.split("\n").forEach(function(e,s,i){if(e.startsWith("*"));else if(e.startsWith(">"));else if(e.startsWith("<")){e.replace("< ","");e.includes("HTTP/")&&(t.code=parseInt(e.replace(new RegExp("HTTP/[^s]+ "),"")))}else r+=e});try{t.body=JSON.parse(r)}catch(e){t.body=r}finally{return t}}else try{t=JSON.parse(e)}catch(s){return e}finally{return t}}},{key:"info",value:function(e){if("xhr"==this._mode){var s=new XMLHttpRequest;if(!_isset(e,"function")){s.open("GET",this.host,!1),this._auth&&this._setAuthHeader(s),s.send();try{var t=JSON.parse(s.response)}catch(e){t=s.response}return{state:s.status,response:t}}s.addEventListener("load",function(t){try{var r=JSON.parse(s.response)}catch(e){r=s.response}e({state:s.status,response:r})}),s.open("GET",this.host),this._auth&&this._setAuthHeader(s),s.send()}}},{key:"allDbs",value:function(e){if("xhr"==this._mode){var s=new XMLHttpRequest;if(!_isset(e,"function")){s.open("GET",this.host+"_all_dbs",!1),this._auth&&this._setAuthHeader(s),s.send();try{var t=JSON.parse(s.response)}catch(e){t=s.response}return{state:s.status,response:t}}s.addEventListener("load",function(t){try{var r=JSON.parse(s.response)}catch(e){r=s.response}e({state:s.status,response:r})}),s.open("GET",this.host+"_all_dbs"),this._auth&&this._setAuthHeader(s),s.send()}else _isset(e,"function")}},{key:"getDb",value:function(e,s){if(!_isset(e,"string"))throw new Error("CDBDriver.db() is missing required argument: dbIdentifier!");if("xhr"==this._mode){var t=new XMLHttpRequest;if(!_isset(s,"function")){t.open("GET",this.host+e,!1),this._auth&&this._setAuthHeader(t),t.send();try{var r=JSON.parse(t.response)}catch(e){r=t.response}return{state:t.status,response:r}}t.addEventListener("load",function(e){try{var r=JSON.parse(t.response)}catch(e){r=t.response}s({state:t.status,response:r})}),t.open("GET",this.host+e),this._auth&&this._setAuthHeader(t),t.send()}}},{key:"createDb",value:function(e,s){if(!_isset(e,"string"))throw new Error("CDBDriver.createDb() is missing required argument: dbIdentifier!");if("xhr"==this._mode){var t=new XMLHttpRequest;if(!_isset(s,"function")){t.open("PUT",this.host+e,!1),this._auth&&this._setAuthHeader(t),t.send();try{var r=JSON.parse(t.response)}catch(e){r=t.response}return{state:t.status,response:r}}t.addEventListener("load",function(e){try{var r=JSON.parse(t.response)}catch(e){r=t.response}s({state:t.status,response:r})}),t.open("PUT",this.host),this._auth&&this._setAuthHeader(t),t.send()}}},{key:"getDocs",value:function(e,s){if(!_isset(e,"string"))throw new Error("CDBDriver.getDocs() is missing required argument: dbIdentifier!");if("xhr"==this._mode){var t=new XMLHttpRequest;if(!_isset(s,"function")){t.open("GET",this.host+e+"/_all_docs",!1),this._auth&&this._setAuthHeader(t),t.send();try{var r=JSON.parse(t.response)}catch(e){r=t.response}return{state:t.status,response:r}}t.addEventListener("load",function(e){try{var r=JSON.parse(t.response)}catch(e){r=t.response}s({state:t.status,response:r})}),t.open("GET",this.host+e+"/_all_docs"),this._auth&&this._setAuthHeader(t),t.send()}}},{key:"storeDoc",value:function(e,s,t){if(!_isset(e,"string"))throw new Error("CDBDriver.storeDoc() is missing required argument: dbIdentifier!");if(!_isset(s,"object"))throw new Error("CDBDriver.storeDoc() is missing required argument: data!");if("xhr"==this._mode){var r=new XMLHttpRequest;if(!_isset(t,"function")){r.open("POST",this.host+e,!1),this._auth&&this._setAuthHeader(r),r.setRequestHeader("Content-Type","application/json"),r.send(JSON.stringify(s));try{var i=JSON.parse(r.response)}catch(e){i=r.response}return{state:r.status,response:i}}r.addEventListener("load",function(e){try{var s=JSON.parse(r.response)}catch(e){s=r.response}t({state:r.status,response:s})}),r.open("POST",this.host+e),this._auth&&this._setAuthHeader(r),r.setRequestHeader("Content-Type","application/json"),r.send(JSON.stringify(s))}}},{key:"getDoc",value:function(e,s,t){if(!_isset(e,"string"))throw new Error("CDBDriver.getDoc() is missing required argument: dbIdentifier!");if(!_isset(s,"string"))throw new Error("CDBDriver.getDoc() is missing required argument: docIdentifier!");if("xhr"==this._mode){var r=new XMLHttpRequest;if(!_isset(t,"function")){r.open("GET",this.host+e+"/"+s,!1),this._auth&&this._setAuthHeader(r),r.send();try{var i=JSON.parse(r.response)}catch(e){i=r.response}return{state:r.status,response:i}}r.addEventListener("load",function(e){try{var s=JSON.parse(r.response)}catch(e){s=r.response}t({state:r.status,response:s})}),r.open("GET",this.host+e+"/"+s),this._auth&&this._setAuthHeader(r),r.send()}}},{key:"deleteDoc",value:function(e,s,t,r){if(!_isset(e,"string"))throw new Error("CDBDriver.deleteDoc() is missing required argument: dbIdentifier!");if(!_isset(s,"string"))throw new Error("CDBDriver.deleteDoc() is missing required argument: docIdentifier!");if(!_isset(t,"string"))throw new Error("CDBDriver.deleteDoc() is missing required argument: docRevision!");if("xhr"==this._mode){var i=new XMLHttpRequest;if(!_isset(r,"function")){i.open("DELETE",this.host+e+"/"+s+"?rev="+t,!1),this._auth&&this._setAuthHeader(i),i.send();try{var n=JSON.parse(i.response)}catch(e){n=i.response}return{state:i.status,response:n}}i.addEventListener("load",function(e){try{var s=JSON.parse(i.response)}catch(e){s=i.response}r({state:i.status,response:s})}),i.open("DELETE",this.host+e+"/"+s+"?rev="+t),this._auth&&this._setAuthHeader(i),i.send()}}},{key:"updateDoc",value:function(e,s,t,r,i){if(!_isset(e,"string"))throw new Error("CDBDriver.updateDoc() is missing required argument: dbIdentifier!");if(!_isset(s,"string"))throw new Error("CDBDriver.updateDoc() is missing required argument: docIdentifier!");if(!_isset(t,"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")){n.open("PUT",this.host+e+"/"+s+"?rev="+t,!1),this._auth&&this._setAuthHeader(n),n.setRequestHeader("Content-Type","application/json"),n.send(JSON.stringify(r));try{var a=JSON.parse(n.response)}catch(e){a=n.response}return{state:n.status,response:a}}n.addEventListener("load",function(e){try{var s=JSON.parse(n.response)}catch(e){s=n.response}i({state:n.status,response:s})}),n.open("PUT",this.host+e+"/"+s+"?rev="+t),this._auth&&this._setAuthHeader(n),n.setRequestHeader("Content-Type","application/json"),n.send(JSON.stringify(r))}}},{key:"storeUser",value:function(e,s){if(!_isset(e.username,"string"))throw new Error("CDBDriver.storeUser() is missing required argument: username!");if(!_isset(e.password,"string"))throw new Error("CDBDriver.storeUser() is missing required argument: password!");var t={_id:"org.couchdb.user:"+e.username,name:e.username,roles:_isset(e.roles,"object")?e.roles:[],type:"user",password:e.password};if(_isset(e.additionals,"object"))for(var r in e.additionals)e.additionals.hasOwnProperty(r)&&!t.hasOwnProperty(r)&&(t[r]=e.additionals[r]);if("xhr"==this._mode){var i=new XMLHttpRequest;if(!_isset(s,"function")){i.open("PUT",this.host+"_users/"+t._id,!1),this._auth&&this._setAuthHeader(i),i.setRequestHeader("Content-Type","application/json"),i.send(JSON.stringify(t));try{var n=JSON.parse(i.response)}catch(e){n=i.response}return{state:i.status,response:n}}i.addEventListener("load",function(e){try{var t=JSON.parse(i.response)}catch(e){t=i.response}s({state:i.status,response:t})}),i.open("PUT",this.host+"_users/"+t._id),this._auth&&this._setAuthHeader(i),i.setRequestHeader("Content-Type","application/json"),i.send(JSON.stringify(t))}}},{key:"storeAdmin",value:function(e,s,t){if(!_isset(e,"string"))throw new Error("CDBDriver.storeUser() is missing required argument: username!");if(!_isset(s,"string"))throw new Error("CDBDriver.storeUser() is missing required argument: password!");if(this.legacy)var r=this.host+"_config/admins/"+e;else r=this.host+"_node/_local/_config/admins/"+e;if("xhr"==this._mode){var i=new XMLHttpRequest;if(!_isset(t,"function")){i.open("PUT",r,!1),this._auth&&this._setAuthHeader(i),i.setRequestHeader("Content-Type","application/json"),i.send('"'+s+'"');try{var n=JSON.parse(i.response)}catch(e){n=i.response}return{state:i.status,response:n}}i.addEventListener("load",function(e){try{var s=JSON.parse(i.response)}catch(e){s=i.response}t({state:i.status,response:s})}),i.open("PUT",r),this._auth&&this._setAuthHeader(i),i.setRequestHeader("Content-Type","application/json"),i.send('"'+s+'"')}}}]),e}();try{module.exports=CDBDriver}catch(e){} |
{ | ||
"name": "cdb-driver", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "A driver library for connecting to a CouchDB instance through JavaScript.", | ||
@@ -5,0 +5,0 @@ "main": "app/main.js", |
@@ -1,2 +0,21 @@ | ||
# cdb-driver | ||
A driver library for connecting to a CouchDB instance through JavaScript. | ||
# CDBDriver | ||
**A driver library for connecting to a CouchDB instance through JavaScript.** | ||
[![GitHub stars](https://img.shields.io/github/stars/mcstreetguy/cdb-driver.svg?style=social&logo=github&label=Stars)](https://github.com/MCStreetguy/cdb-driver) | ||
![NPM Downloads](https://img.shields.io/npm/dt/cdb-driver.svg) | ||
[![GitHub package version](https://img.shields.io/github/package-json/v/mcstreetguy/cdb-driver.svg)](https://www.npmjs.com/package/cdb-driver) | ||
![NPM License](https://img.shields.io/npm/l/cdb-driver.svg) | ||
[![GitHub issues](https://img.shields.io/github/issues/mcstreetguy/cdb-driver.svg)](https://github.com/MCStreetguy/cdb-driver/issues) | ||
![GitHub last commit](https://img.shields.io/github/last-commit/mcstreetguy/cdb-driver.svg) | ||
[![Documentation Status](https://readthedocs.org/projects/cdbdriver/badge/?version=latest)](http://cdbdriver.readthedocs.io/en/latest/?badge=latest) | ||
CouchDB seems the perfect database for JavaScript applications since it uses | ||
JSON as data structure. On first sight, this makes it really easy to interact | ||
with a CouchDB instance. But endless encapsulation of asynchroneous requests | ||
and their callbacks gets annoying fast. | ||
Thus this library provides both, asynchroneous and synchroneous methods. | ||
Performing synchroneous requests on the main thread is deprecated and should not | ||
be used in production environments, even if its provided by this library. | ||
**For further information on how to use this library check out the documentation.** |
38473
9
22