!function(o,e,g){"undefined"!=typeof module&&module.exports?module.exports=g():"function"==typeof define&&define.amd?define(g):e[o]=g()}("reqwest",this,function(){function handleReadyState(o,e,g){return function(){return o._aborted?g(o.request):(o.request&&4==o.request[readyState]&&(o.request.onreadystatechange=noop,twoHundo.test(o.request.status)?e(o.request):g(o.request)),void 0)}}function setHeaders(o,e){var g,s=e.headers||{};s.Accept=s.Accept||defaultHeaders.accept[e.type]||defaultHeaders.accept["*"],e.crossOrigin||s[requestedWith]||(s[requestedWith]=defaultHeaders.requestedWith),s[contentType]||(s[contentType]=e.contentType||defaultHeaders.contentType);for(g in s)s.hasOwnProperty(g)&&"setRequestHeader"in o&&o.setRequestHeader(g,s[g])}function setCredentials(o,e){"undefined"!=typeof e.withCredentials&&"undefined"!=typeof o.withCredentials&&(o.withCredentials=!!e.withCredentials)}function generalCallback(o){lastValue=o}function urlappend(o,e){return o+(/\?/.test(o)?"&":"?")+e}function handleJsonp(o,e,g,s){var r=uniqid++,t=o.jsonpCallback||"callback",a=o.jsonpCallbackName||reqwest.getcallbackPrefix(r),l=new RegExp("((^|\\?|&)"+t+")=([^&]+)"),c=s.match(l),i=doc.createElement("script"),n=0,m=-1!==navigator.userAgent.indexOf("MSIE 10.0");return c?"?"===c[3]?s=s.replace(l,"$1="+a):a=c[3]:s=urlappend(s,t+"="+a),win[a]=generalCallback,i.type="text/javascript",i.src=s,i.async=!0,"undefined"==typeof i.onreadystatechange||m||(i.htmlFor=i.id="_reqwest_"+r),i.onload=i.onreadystatechange=function(){return i[readyState]&&"complete"!==i[readyState]&&"loaded"!==i[readyState]||n?!1:(i.onload=i.onreadystatechange=null,i.onclick&&i.onclick(),e(lastValue),lastValue=void 0,head.removeChild(i),n=1,void 0)},head.appendChild(i),{abort:function(){i.onload=i.onreadystatechange=null,g({},"Request is aborted: timeout",{}),lastValue=void 0,head.removeChild(i),n=1}}}function getRequest(o,e){var g,s=this.o,r=(s.method||"GET").toUpperCase(),t="string"==typeof s?s:s.url,a=s.processData!==!1&&s.data&&"string"!=typeof s.data?reqwest.toQueryString(s.data):s.data||null,l=!1;return"jsonp"!=s.type&&"GET"!=r||!a||(t=urlappend(t,a),a=null),"jsonp"==s.type?handleJsonp(s,o,e,t):(g=s.xhr&&s.xhr(s)||xhr(s),g.open(r,t,s.async===!1?!1:!0),setHeaders(g,s),setCredentials(g,s),win[xDomainRequest]&&g instanceof win[xDomainRequest]?(g.onload=o,g.onerror=e,g.onprogress=function(){},l=!0):g.onreadystatechange=handleReadyState(this,o,e),s.before&&s.before(g),l?setTimeout(function(){g.send(a)},200):g.send(a),g)}function Reqwest(o,e){this.o=o,this.fn=e,init.apply(this,arguments)}function setType(o){return o.match("json")?"json":o.match("javascript")?"js":o.match("text")?"html":o.match("xml")?"xml":void 0}function init(o,fn){function complete(e){for(o.timeout&&clearTimeout(self.timeout),self.timeout=null;self._completeHandlers.length>0;)self._completeHandlers.shift()(e)}function success(resp){var type=o.type||setType(resp.getResponseHeader("Content-Type"));resp="jsonp"!==type?self.request:resp;var filteredResponse=globalSetupOptions.dataFilter(resp.responseText,type),r=filteredResponse;try{resp.responseText=r}catch(e){}if(r)switch(type){case"json":try{resp=win.JSON?win.JSON.parse(r):eval("("+r+")")}catch(err){return error(resp,"Could not parse JSON in response",err)}break;case"js":resp=eval(r);break;case"html":resp=r;break;case"xml":resp=resp.responseXML&&resp.responseXML.parseError&&resp.responseXML.parseError.errorCode&&resp.responseXML.parseError.reason?null:resp.responseXML}for(self._responseArgs.resp=resp,self._fulfilled=!0,fn(resp),self._successHandler(resp);self._fulfillmentHandlers.length>0;)resp=self._fulfillmentHandlers.shift()(resp);complete(resp)}function error(o,e,g){for(o=self.request,self._responseArgs.resp=o,self._responseArgs.msg=e,self._responseArgs.t=g,self._erred=!0;self._errorHandlers.length>0;)self._errorHandlers.shift()(o,e,g);complete(o)}this.url="string"==typeof o?o:o.url,this.timeout=null,this._fulfilled=!1,this._successHandler=function(){},this._fulfillmentHandlers=[],this._errorHandlers=[],this._completeHandlers=[],this._erred=!1,this._responseArgs={};var self=this;fn=fn||function(){},o.timeout&&(this.timeout=setTimeout(function(){self.abort()},o.timeout)),o.success&&(this._successHandler=function(){o.success.apply(o,arguments)}),o.error&&this._errorHandlers.push(function(){o.error.apply(o,arguments)}),o.complete&&this._completeHandlers.push(function(){o.complete.apply(o,arguments)}),this.request=getRequest.call(this,success,error)}function reqwest(o,e){return new Reqwest(o,e)}function normalize(o){return o?o.replace(/\r?\n/g,"\r\n"):""}function serial(o,e){var g,s,r,t,a=o.name,l=o.tagName.toLowerCase(),c=function(o){o&&!o.disabled&&e(a,normalize(o.attributes.value&&o.attributes.value.specified?o.value:o.text))};if(!o.disabled&&a)switch(l){case"input":/reset|button|image|file/i.test(o.type)||(g=/checkbox/i.test(o.type),s=/radio/i.test(o.type),r=o.value,(!(g||s)||o.checked)&&e(a,normalize(g&&""===r?"on":r)));break;case"textarea":e(a,normalize(o.value));break;case"select":if("select-one"===o.type.toLowerCase())c(o.selectedIndex>=0?o.options[o.selectedIndex]:null);else for(t=0;o.length&&t0)){var e=g.shift();e()}},!0),function(o){g.push(o),window.postMessage("process-tick","*")}}return function(o){setTimeout(o,0)}}(),g.title="browser",g.browser=!0,g.env={},g.argv=[],g.binding=function(){throw new Error("process.binding is not supported")},g.cwd=function(){return"/"},g.chdir=function(){throw new Error("process.chdir is not supported")}},{}],2:[function(o,e){"use strict";function g(o){function e(o){return null===n?(u.push(o),void 0):(r(function(){var e=n?o.onFulfilled:o.onRejected;if(null===e)return(n?o.resolve:o.reject)(w),void 0;var g;try{g=e(w)}catch(s){return o.reject(s),void 0}o.resolve(g)}),void 0)}function t(o){m||a(o)}function a(o){if(null===n)try{if(o===p)throw new TypeError("A promise cannot be resolved with itself.");if(o&&("object"==typeof o||"function"==typeof o)){var e=o.then;if("function"==typeof e)return m=!0,e.call(o,a,c),void 0}n=!0,w=o,i()}catch(g){c(g)}}function l(o){m||c(o)}function c(o){null===n&&(n=!1,w=o,i())}function i(){for(var o=0,g=u.length;g>o;o++)e(u[o]);u=null}if(!(this instanceof g))return new g(o);if("function"!=typeof o)throw new TypeError("not a function");var n=null,m=!1,w=null,u=[],p=this;this.then=function(o,r){return new g(function(g,t){e(new s(o,r,g,t))})};try{o(t,l)}catch(d){l(d)}}function s(o,e,g,s){this.onFulfilled="function"==typeof o?o:null,this.onRejected="function"==typeof e?e:null,this.resolve=g,this.reject=s}var r=o("./lib/next-tick");e.exports=g},{"./lib/next-tick":4}],3:[function(o,e){"use strict";var g=o("./core.js"),s=o("./lib/next-tick");e.exports=g,g.from=function(o){return o instanceof g?o:new g(function(e){e(o)})},g.denodeify=function(o){return function(){var e=this,s=Array.prototype.slice.call(arguments);return new g(function(g,r){s.push(function(o,e){o?r(o):g(e)}),o.apply(e,s)})}},g.nodeify=function(o){return function(){var e=Array.prototype.slice.call(arguments),r="function"==typeof e[e.length-1]?e.pop():null;try{return o.apply(this,arguments).nodeify(r)}catch(t){if(null==r)return new g(function(o,e){e(t)});s(function(){r(t)})}}},g.all=function(){var o=Array.prototype.slice.call(1===arguments.length&&Array.isArray(arguments[0])?arguments[0]:arguments);return new g(function(e,g){function s(t,a){try{if(a&&("object"==typeof a||"function"==typeof a)){var l=a.then;if("function"==typeof l)return l.call(a,function(o){s(t,o)},g),void 0}o[t]=a,0===--r&&e(o)}catch(c){g(c)}}if(0===o.length)return e([]);for(var r=o.length,t=0;te;e++)if(e in this&&this[e]===o)return e;return-1};window.InfluxDB=o=function(){function o(o){var g;o||(o={}),this.host=o.host||"localhost",this.hosts=o.hosts||[this.host],this.port=o.port||8086,this.username=o.username||"root",this.password=o.password||"root",this.database=o.database,this.ssl=o.ssl||!1,this.max_retries=o.max_retries||20,this.isCrossOrigin=(g=window.location.host,e.call(this.hosts,g)<0),this.username=encodeURIComponent(this.username),this.password=encodeURIComponent(this.password)}return o.prototype.getDatabases=function(){return this.get(this.path("db"))},o.prototype.createDatabase=function(o,e){var g;return g={name:o},this.post(this.path("db"),g,e)},o.prototype.deleteDatabase=function(o){return this["delete"](this.path("db/"+o))},o.prototype.getClusterConfiguration=function(){return this.get(this.path("cluster/configuration"))},o.prototype.createDatabaseConfig=function(o,e,g){return this.post(this.path("cluster/database_configs/"+o),e,g)},o.prototype.getDatabaseUsers=function(o){return this.get(this.path("db/"+o+"/users"))},o.prototype.createUser=function(o,e,g,s){var r;return r={name:e,password:g},this.post(this.path("db/"+o+"/users"),r,s)},o.prototype.deleteDatabaseUser=function(o,e){return this["delete"](this.path("db/"+o+"/users/"+e))},o.prototype.getDatabaseUser=function(o,e){return this.get(this.path("db/"+o+"/users/"+e))},o.prototype.updateDatabaseUser=function(o,e,g,s){return this.post(this.path("db/"+o+"/users/"+e),g,s)},o.prototype.authenticateDatabaseUser=function(){return this.get(this.path("db/"+this.database+"/authenticate"))},o.prototype.getClusterAdmins=function(){return this.get(this.path("cluster_admins"))},o.prototype.deleteClusterAdmin=function(o){return this["delete"](this.path("cluster_admins/"+o))},o.prototype.createClusterAdmin=function(o,e){var g;return g={name:o,password:e},this.post(this.path("cluster_admins"),g)},o.prototype.updateClusterAdmin=function(o,e,g){return this.post(this.path("cluster_admins/"+o),e,g)},o.prototype.authenticateClusterAdmin=function(){return this.get(this.path("cluster_admins/authenticate"))},o.prototype.getContinuousQueries=function(o){return this.get(this.path("db/"+o+"/continuous_queries"))},o.prototype.deleteContinuousQuery=function(o,e){return this["delete"](this.path("db/"+o+"/continuous_queries/"+e))},o.prototype.getClusterServers=function(){return this.get(this.path("cluster/servers"))},o.prototype.getClusterShardSpaces=function(){return this.get(this.path("cluster/shard_spaces"))},o.prototype.getClusterShards=function(){return this.get(this.path("cluster/shards"))},o.prototype.createClusterShard=function(o,e,g,s,r,t){var a;return a={database:g,spaceName:s,startTime:o,endTime:e,longTerm:longTerm,shards:[{serverIds:r}]},this.post(this.path("cluster/shards"),a,t)},o.prototype.deleteClusterShard=function(o,e){var g;return g={serverIds:e},this["delete"](this.path("cluster/shards/"+o),g)},o.prototype.getInterfaces=function(){return this.get(this.path("interfaces"))},o.prototype.readPoint=function(o,e,g){var s;return s="SELECT "+o+" FROM "+e+";",this.get(this.path("db/"+this.database+"/series",{q:s}),g)},o.prototype._readPoint=function(o,e){return this.get(this.path("db/"+this.database+"/series",{q:o}),e)},o.prototype.query=function(o,e){return this.get(this.path("db/"+this.database+"/series",{q:o}),e)},o.prototype.get=function(o,e){var g=this;return new Promise(function(s,r){return g.retry(s,r,function(){return reqwest({method:"get",type:"json",url:g.url(o),crossOrigin:g.isCrossOrigin,success:function(o){return s(o),e?e(g.formatPoints(o)):void 0}})})})},o.prototype.post=function(o,e){var g=this;return new Promise(function(s,r){return g.retry(s,r,function(){return reqwest({method:"post",type:"json",url:g.url(o),crossOrigin:g.isCrossOrigin,contentType:"application/json",data:JSON.stringify(e),success:function(o){return s(o)}})})})},o.prototype["delete"]=function(o,e){var g=this;return new Promise(function(s,r){return g.retry(s,r,function(){return reqwest({method:"delete",type:"json",url:g.url(o),crossOrigin:g.isCrossOrigin,data:JSON.stringify(e),success:function(o){return s(o),"undefined"!=typeof callback&&null!==callback?callback(o):void 0}})})})},o.prototype.formatPoints=function(o){return o.map(function(o){var e;return e={name:o.name,points:o.points.map(function(e){var g,s;return g={},o.columns.forEach(function(o,s){return g[o]=e[s]}),s=new Date(0),s.setUTCSeconds(Math.round(g.time/1e3)),g.time=s,g})}})},o.prototype.writePoint=function(o,e,g,s){var r,t,a,l,c;null==g&&(g={}),t={points:[],name:o,columns:[]},l=[];for(a in e)c=e[a],l.push(c),t.columns.push(a);return t.points.push(l),r=[t],this.post(this.path("db/"+this.database+"/series"),r,s)},o.prototype.writeSeries=function(o,e){return this.post(this.path("db/"+this.database+"/series"),o,e)},o.prototype.path=function(o,e){var g;return g=""+o+"?u="+this.username+"&p="+this.password,null!=e&&e.q&&(g+="&q="+encodeURIComponent(e.q)),g},o.prototype.url=function(o){var e;return e=this.hosts.shift(),this.hosts.push(e),""+(this.ssl?"https":"http")+"://"+e+":"+this.port+"/"+o},o.prototype.retry=function(o,e,g,s,r){var t=this;return null==s&&(s=10),null==r&&(r=this.max_retries),g().then(void 0,function(a){return 0===a.status?setTimeout(function(){return t.retry(o,e,g,Math.min(2*s,3e4),r-1)},s):e(a)})},o}()}.call(this),window.InfluxDB.VERSION="0.0.16",function(){}.call(this);