1 line
18 KiB
JavaScript
1 line
18 KiB
JavaScript
!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&&t<o.length;t++)o.options[t].selected&&c(o.options[t])}}function eachFormElement(){var o,e,g=this,s=function(o,e){var s,r,t;for(s=0;s<e.length;s++)for(t=o[byTag](e[s]),r=0;r<t.length;r++)serial(t[r],g)};for(e=0;e<arguments.length;e++)o=arguments[e],/input|select|textarea/i.test(o.tagName)&&serial(o,g),s(o,["input","select","textarea"])}function serializeQueryString(){return reqwest.toQueryString(reqwest.serializeArray.apply(null,arguments))}function serializeHash(){var o={};return eachFormElement.apply(function(e,g){e in o?(o[e]&&!isArray(o[e])&&(o[e]=[o[e]]),o[e].push(g)):o[e]=g},arguments),o}function buildParams(o,e,g,s){var r,t,a,l=/\[\]$/;if(isArray(e))for(t=0;e&&t<e.length;t++)a=e[t],g||l.test(o)?s(o,a):buildParams(o+"["+("object"==typeof a?t:"")+"]",a,g,s);else if(e&&"[object Object]"===e.toString())for(r in e)buildParams(o+"["+r+"]",e[r],g,s);else s(o,e)}var win=window,doc=document,twoHundo=/^(20\d|1223)$/,byTag="getElementsByTagName",readyState="readyState",contentType="Content-Type",requestedWith="X-Requested-With",head=doc[byTag]("head")[0],uniqid=0,callbackPrefix="reqwest_"+ +new Date,lastValue,xmlHttpRequest="XMLHttpRequest",xDomainRequest="XDomainRequest",noop=function(){},isArray="function"==typeof Array.isArray?Array.isArray:function(o){return o instanceof Array},defaultHeaders={contentType:"application/x-www-form-urlencoded",requestedWith:xmlHttpRequest,accept:{"*":"text/javascript, text/html, application/xml, text/xml, */*",xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript",js:"application/javascript, text/javascript"}},xhr=function(o){if(o.crossOrigin===!0){var e=win[xmlHttpRequest]?new XMLHttpRequest:null;if(e&&"withCredentials"in e)return e;if(win[xDomainRequest])return new XDomainRequest;throw new Error("Browser does not support cross-origin requests")}return win[xmlHttpRequest]?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP")},globalSetupOptions={dataFilter:function(o){return o}};return Reqwest.prototype={abort:function(){this._aborted=!0,this.request.abort()},retry:function(){init.call(this,this.o,this.fn)},then:function(o,e){return o=o||function(){},e=e||function(){},this._fulfilled?this._responseArgs.resp=o(this._responseArgs.resp):this._erred?e(this._responseArgs.resp,this._responseArgs.msg,this._responseArgs.t):(this._fulfillmentHandlers.push(o),this._errorHandlers.push(e)),this},always:function(o){return this._fulfilled||this._erred?o(this._responseArgs.resp):this._completeHandlers.push(o),this},fail:function(o){return this._erred?o(this._responseArgs.resp,this._responseArgs.msg,this._responseArgs.t):this._errorHandlers.push(o),this}},reqwest.serializeArray=function(){var o=[];return eachFormElement.apply(function(e,g){o.push({name:e,value:g})},arguments),o},reqwest.serialize=function(){if(0===arguments.length)return"";var o,e,g=Array.prototype.slice.call(arguments,0);return o=g.pop(),o&&o.nodeType&&g.push(o)&&(o=null),o&&(o=o.type),e="map"==o?serializeHash:"array"==o?reqwest.serializeArray:serializeQueryString,e.apply(null,g)},reqwest.toQueryString=function(o,e){var g,s,r=e||!1,t=[],a=encodeURIComponent,l=function(o,e){e="function"==typeof e?e():null==e?"":e,t[t.length]=a(o)+"="+a(e)};if(isArray(o))for(s=0;o&&s<o.length;s++)l(o[s].name,o[s].value);else for(g in o)o.hasOwnProperty(g)&&buildParams(g,o[g],r,l);return t.join("&").replace(/%20/g,"+")},reqwest.getcallbackPrefix=function(){return callbackPrefix},reqwest.compat=function(o,e){return o&&(o.type&&(o.method=o.type)&&delete o.type,o.dataType&&(o.type=o.dataType),o.jsonpCallback&&(o.jsonpCallbackName=o.jsonpCallback)&&delete o.jsonpCallback,o.jsonp&&(o.jsonpCallback=o.jsonp)),new Reqwest(o,e)},reqwest.ajaxSetup=function(o){o=o||{};for(var e in o)globalSetupOptions[e]=o[e]},reqwest}),function(o){if("function"==typeof bootstrap)bootstrap("promise",o);else if("object"==typeof exports)module.exports=o();else if("function"==typeof define&&define.amd)define(o);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makePromise=o}else"undefined"!=typeof window?window.Promise=o():global.Promise=o()}(function(){return function(o,e,g){function s(g,t){if(!e[g]){if(!o[g]){var a="function"==typeof require&&require;if(!t&&a)return a(g,!0);if(r)return r(g,!0);throw new Error("Cannot find module '"+g+"'")}var l=e[g]={exports:{}};o[g][0].call(l.exports,function(e){var r=o[g][1][e];return s(r?r:e)},l,l.exports)}return e[g].exports}for(var r="function"==typeof require&&require,t=0;t<g.length;t++)s(g[t]);return s}({1:[function(o,e){var g=e.exports={};g.nextTick=function(){var o="undefined"!=typeof window&&window.setImmediate,e="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(o)return function(o){return window.setImmediate(o)};if(e){var g=[];return window.addEventListener("message",function(o){if(o.source===window&&"process-tick"===o.data&&(o.stopPropagation(),g.length>0)){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;t<o.length;t++)s(t,o[t])})},g.prototype.done=function(){var o=arguments.length?this.then.apply(this,arguments):this;o.then(null,function(o){s(function(){throw o})})},g.prototype.nodeify=function(o){return null==o?this:(this.then(function(e){s(function(){o(null,e)})},function(e){s(function(){o(e)})}),void 0)}},{"./core.js":2,"./lib/next-tick":4}],4:[function(o,e){!function(o){"use strict";e.exports="function"==typeof setImmediate?function(o){setImmediate(o)}:"undefined"!=typeof o&&o&&"function"==typeof o.nextTick?function(e){o.nextTick(e)}:function(o){setTimeout(o,0)}}(o("__browserify_process"))},{__browserify_process:1}]},{},[3])(3)}),function(){var o,e=[].indexOf||function(o){for(var e=0,g=this.length;g>e;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); |