@influxdata/influxdb-client-browser 1.18.0 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Point.d.ts +3 -0
- package/dist/Point.d.ts.map +1 -1
- package/dist/all.d.ts +3 -0
- package/dist/impl/version.d.ts +1 -1
- package/dist/index.browser.js +2 -2
- package/dist/index.browser.js.gz +0 -0
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.gz +0 -0
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.gz +0 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.gz +0 -0
- package/dist/index.mjs.map +1 -1
- package/dist/influxdb.js +26 -17
- package/dist/influxdb.js.gz +0 -0
- package/dist/influxdb.js.map +1 -1
- package/dist/influxdb.min.js +1 -1
- package/dist/influxdb.min.js.gz +0 -0
- package/dist/influxdb.min.js.map +1 -1
- package/package.json +3 -3
package/dist/influxdb.min.js
CHANGED
|
@@ -13,5 +13,5 @@ var influxdb=function(t){"use strict";function e(){var t=new TextDecoder("utf-8"
|
|
|
13
13
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
15
|
***************************************************************************** */
|
|
16
|
-
var s=function(t,e){return(s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(t,e)};function u(t,e){function r(){this.constructor=t}s(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var a=function(){return(a=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function l(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{a(n.next(t))}catch(t){o(t)}}function u(t){try{a(n.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,u)}a((n=n.apply(t,e||[])).next())}))}function c(t,e){var r,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}}var f=[404,408,425,429,500,502,503,504];function h(t){return f.includes(t)}var p=function(t){function e(r){var n=t.call(this,r)||this;return n.name="IllegalArgumentError",Object.setPrototypeOf(n,e.prototype),n}return u(e,t),e}(Error),d=function(t){function e(r,n,i,o,s,u){var a=t.call(this)||this;if(a.statusCode=r,a.statusMessage=n,a.body=i,a.contentType=s,Object.setPrototypeOf(a,e.prototype),u)a.message=u;else if(i){if(null==s?void 0:s.startsWith("application/json"))try{a.json=JSON.parse(i),a.message=a.json.message,a.code=a.json.code}catch(t){}a.message||(a.message=r+" "+n+" : "+i)}else a.message=r+" "+n;return a.name="HttpError",a.setRetryAfter(o),a}return u(e,t),e.prototype.setRetryAfter=function(t){"string"==typeof t&&/^[0-9]+$/.test(t)?this._retryAfter=parseInt(t):this._retryAfter=0},e.prototype.canRetry=function(){return h(this.statusCode)},e.prototype.retryAfter=function(){return this._retryAfter},e}(Error),y=["ECONNRESET","ENOTFOUND","ESOCKETTIMEDOUT","ETIMEDOUT","ECONNREFUSED","EHOSTUNREACH","EPIPE"];function g(t,e){if(t){var r=void 0;return"function"==typeof t.retryAfter?t.retryAfter():(r=0,e&&e>0?r+Math.round(Math.random()*e):r)}return 0}var v=function(t){function e(){var r=t.call(this)||this;return Object.setPrototypeOf(r,e.prototype),r.name="RequestTimedOutError",r.message="Request timed out",r}return u(e,t),e.prototype.canRetry=function(){return!0},e.prototype.retryAfter=function(){return 0},e}(Error),m=function(t){function e(){var r=t.call(this)||this;return r.name="AbortError",Object.setPrototypeOf(r,e.prototype),r.message="Response aborted",r}return u(e,t),e.prototype.canRetry=function(){return!0},e.prototype.retryAfter=function(){return 0},e}(Error),w=function(t){return t},b={boolean:function(t){return"true"===t},unsignedLong:function(t){return""===t?null:+t},long:function(t){return""===t?null:+t},double:function(t){switch(t){case"":return null;case"+Inf":return Number.POSITIVE_INFINITY;case"-Inf":return Number.NEGATIVE_INFINITY;default:return+t}},string:w,base64Binary:w,duration:function(t){return""===t?null:t},"dateTime:RFC3339":function(t){return""===t?null:t}};var x=function(){function t(t){t.forEach((function(t,e){return t.index=e})),this.columns=t}return t.prototype.column=function(t){for(var e=0;e<this.columns.length;e++){var r=this.columns[e];if(r.label===t)return r}throw new p("Column "+t+" not found!")},t.prototype.toObject=function(t){for(var e,r={},n=0;n<this.columns.length&&n<t.length;n++){var i=t[n],o=this.columns[n];""===i&&o.defaultValue&&(i=o.defaultValue),r[o.label]=(null!==(e=b[o.dataType])&&void 0!==e?e:w)(i)}return r},t}();function T(t){return new x(t)}function O(t){var e,r,i=(new n).withReuse(),s=!0,u=0;return{error:function(e){t.error(e)},next:function(n){if(""===n)s=!0,e=void 0;else{var a=i.splitLine(n),l=i.lastSplitLength;if(s){if(!e){e=new Array(l);for(var c=0;c<l;c++)e[c]=o()}if(a[0].startsWith("#")){if("#datatype"===a[0])for(c=1;c<l;c++)e[c].dataType=a[c];else if("#default"===a[0])for(c=1;c<l;c++)e[c].defaultValue=a[c];else if("#group"===a[0])for(c=1;c<l;c++)e[c].group="t"===a[c][0]}else{""===a[0]?(u=1,e=e.slice(1)):u=0;for(var c=u;c<l;c++)e[c-u].label=a[c];r=T(e),s=!1}}else t.next(a.slice(u,l),r)}},complete:function(){t.complete()},useCancellable:function(e){t.useCancellable&&t.useCancellable(e)}}}var R={retryJitter:200,minRetryDelay:5e3,maxRetryDelay:125e3,exponentialBase:5,randomRetry:!0},E={batchSize:1e3,flushInterval:6e4,writeFailed:function(){},writeSuccess:function(){},maxRetries:5,maxRetryTime:18e4,maxBufferLines:32e3,retryJitter:200,minRetryDelay:5e3,maxRetryDelay:125e3,exponentialBase:2,gzipThreshold:1e3,randomRetry:!0};function S(t,e){return function(r){for(var n="",i=0,o=0;o<r.length;){var s=t.indexOf(r[o]);s>=0&&(n+=r.substring(i,o),n+=e[s],i=o+1),o++}return 0==i?r:(i<r.length&&(n+=r.substring(i,r.length)),n)}}var D,A,C,_={measurement:S(", \n\r\t",["\\,","\\ ","\\n","\\r","\\t"]),quoted:(D='"\\',A=['\\"',"\\\\"],C=S(D,A),function(t){return'"'+C(t)+'"'}),tag:S(", =\n\r\t",["\\,","\\ ","\\=","\\n","\\r","\\t"])};var P=Date.now(),B=0;function L(){var t=Date.now();t!==P?(P=t,B=0):B++;var e=String(B);return String(t)+"000000000".substr(0,6-e.length)+e}function j(){return String(Date.now())+"000000000".substr(0,3)}function F(){return String(Date.now())}function I(){return String(Math.floor(Date.now()/1e3))}var M={s:I,ms:F,us:j,ns:L,seconds:I,millis:F,micros:j,nanos:L},N={s:function(t){return""+Math.floor(t.getTime()/1e3)},ms:function(t){return""+t.getTime()},us:function(t){return t.getTime()+"000"},ns:function(t){return t.getTime()+"000000"}};function k(t){return void 0===t?L():"string"==typeof t?t.length>0?t:void 0:t instanceof Date?t.getTime()+"000000":String("number"==typeof t?Math.floor(t):t)}var z={error:function(t,e){console.error("ERROR: "+t,e||"")},warn:function(t,e){console.warn("WARN: "+t,e||"")}},U=z,q={error:function(t,e){U.error(t,e)},warn:function(t,e){U.warn(t,e)}};var H=Symbol("FLUX_VALUE"),V=function(){function t(t){this.fluxValue=t}return t.prototype.toString=function(){return this.fluxValue},t.prototype[H]=function(){return this.fluxValue},t}();function W(t){return"object"==typeof t&&"function"==typeof t[H]}function J(t){if(null==t)return"";t=t.toString();var e=void 0,r=0;function n(){void 0===e&&(e=t.substring(0,r))}for(;r<t.length;r++){var i=t.charAt(r);switch(i){case"\r":n(),e+="\\r";break;case"\n":n(),e+="\\n";break;case"\t":n(),e+="\\t";break;case'"':case"\\":n(),e=e+"\\"+i;break;case"$":if(r+1<t.length&&"{"===t.charAt(r+1)){n(),r++,e+="\\${";break}null!=e&&(e+=i);break;default:null!=e&&(e+=i)}}return void 0!==e?e:t}function G(t){if("number"==typeof t){if(!isFinite(t))throw new Error("not a flux float: "+t);return t.toString()}for(var e=String(t),r=!1,n=0,i=e;n<i.length;n++){var o=i[n];if("."!==o){if("."!==o&&"-"!==o&&(o<"0"||o>"9"))throw new Error("not a flux float: "+e)}else{if(r)throw new Error("not a flux float: "+e);r=!r}}return e}function X(t){return'regexp.compile(v: "'+J(t)+'")'}function $(t){return new V(String(t))}function Y(t){if(void 0===t)return"";if(null===t)return"null";if("boolean"==typeof t)return t.toString();if("string"==typeof t)return'"'+J(t)+'"';if("number"==typeof t)return G(t);if("object"==typeof t){if("function"==typeof t[H])return t[H]();if(t instanceof Date)return t.toISOString();if(t instanceof RegExp)return X(t);if(Array.isArray(t))return"["+t.map(Y).join(",")+"]"}return Y(t.toString())}var K="function"==typeof Symbol&&Symbol.observable||"@@observable",Q=function(){function t(t){this.tags={},this.fields={},t&&(this.name=t)}return t.prototype.measurement=function(t){return this.name=t,this},t.prototype.tag=function(t,e){return this.tags[t]=e,this},t.prototype.booleanField=function(t,e){return this.fields[t]=e?"T":"F",this},t.prototype.intField=function(t,e){if("number"!=typeof e){var r;if(isNaN(r=parseInt(String(e))))throw new Error("Expected integer value for field "+t+", but got '"+e+"'!");e=r}return this.fields[t]=Math.floor(e)+"i",this},t.prototype.uintField=function(t,e){if("number"==typeof e){if(e<0||e>Number.MAX_SAFE_INTEGER)throw new Error("uint value out of js unsigned integer range: "+e);this.fields[t]=Math.floor(e)+"u"}else{for(var r=String(e),n=0;n<r.length;n++){var i=r.charCodeAt(n);if(i<48||i>57)throw new Error("uint value has an unsupported character at pos "+n+": "+e)}if(r.length>20||20===r.length&&r.localeCompare("18446744073709551615")>0)throw new Error("uint value out of range: "+r);this.fields[t]=r+"u"}return this},t.prototype.floatField=function(t,e){if("number"!=typeof e){var r;if(isNaN(r=parseFloat(e)))throw new Error("Expected float value for field "+t+", but got '"+e+"'!");e=r}return this.fields[t]=String(e),this},t.prototype.stringField=function(t,e){return null!=e&&("string"!=typeof e&&(e=String(e)),this.fields[t]=_.quoted(e)),this},t.prototype.timestamp=function(t){return this.time=t,this},t.prototype.toLineProtocol=function(t){var e=this;if(this.name){var r="";if(Object.keys(this.fields).sort().forEach((function(t){if(t){var n=e.fields[t];r.length>0&&(r+=","),r+=_.tag(t)+"="+n}})),0!==r.length){var n="",i=t&&t.defaultTags?a(a({},t.defaultTags),this.tags):this.tags;Object.keys(i).sort().forEach((function(t){if(t){var e=i[t];e&&(n+=",",n+=_.tag(t)+"="+_.tag(e))}}));var o=this.time;return o=t&&t.convertTime?t.convertTime(o):k(o),""+_.measurement(this.name)+n+" "+r+(void 0!==o?" "+o:"")}}},t.prototype.toString=function(){var t=this.toLineProtocol(void 0);return t||"invalid point: "+JSON.stringify(this,void 0)},t}(),Z=function(){function t(t){this.options=a(a({},R),t),this.success()}return t.prototype.nextDelay=function(t,e){var r=g(t);if(r&&r>0)return r+Math.round(Math.random()*this.options.retryJitter);if(e&&e>0){if(this.options.randomRetry){for(var n=Math.max(this.options.minRetryDelay,1),i=n*this.options.exponentialBase,o=1;o<e;o++)if(n=i,(i*=this.options.exponentialBase)>=this.options.maxRetryDelay){i=this.options.maxRetryDelay;break}return n+Math.round(Math.random()*(i-n)+Math.random()*this.options.retryJitter)}var s=Math.max(this.options.minRetryDelay,1);for(o=1;o<e;o++)if((s*=this.options.exponentialBase)>=this.options.maxRetryDelay){s=this.options.maxRetryDelay;break}return s+Math.round(Math.random()*this.options.retryJitter)}return this.currentDelay?this.currentDelay=Math.min(Math.max(this.currentDelay*this.options.exponentialBase,1)+Math.round(Math.random()*this.options.retryJitter),this.options.maxRetryDelay):this.currentDelay=this.options.minRetryDelay+Math.round(Math.random()*this.options.retryJitter),this.currentDelay},t.prototype.success=function(){this.currentDelay=void 0},t}();var tt=function(){function t(t,e){this.maxLines=t,this.retryLines=e,this.size=0,this.nextRetryTime=0,this.closed=!1,this._timeoutHandle=void 0}return t.prototype.addLines=function(t,e,r,n){if(!this.closed&&t.length){var i=Date.now()+r;if(n<i&&(r=n-Date.now(),i=n),i>this.nextRetryTime&&(this.nextRetryTime=i),this.first&&this.size+t.length>this.maxLines){var o=this.size,s=.7*o;do{var u=this.first.next;this.size-=this.first.lines.length,this.first.next=void 0,this.first=u,this.first||(this.last=void 0)}while(this.first&&this.size+t.length>s);q.error("RetryBuffer: "+(o-this.size)+" oldest lines removed to keep buffer size under the limit of "+this.maxLines+" lines")}var a={lines:t,retryCount:e,expires:n};this.last?(this.last.next=a,this.last=a):(this.first=a,this.last=a,this.scheduleRetry(r)),this.size+=t.length}},t.prototype.removeLines=function(){if(this.first){var t=this.first;return this.first=this.first.next,t.next=void 0,this.size-=t.lines.length,this.first||(this.last=void 0),t}},t.prototype.scheduleRetry=function(t){var e=this;this._timeoutHandle=setTimeout((function(){var t=e.removeLines();t?e.retryLines(t.lines,t.retryCount,t.expires).then((function(){e.scheduleRetry(1)})).catch((function(t){e.scheduleRetry(e.nextRetryTime-Date.now())})):e._timeoutHandle=void 0}),Math.max(t,0))},t.prototype.flush=function(){return l(this,void 0,void 0,(function(){var t;return c(this,(function(e){switch(e.label){case 0:return(t=this.removeLines())?[4,this.retryLines(t.lines,t.retryCount,t.expires)]:[3,2];case 1:return e.sent(),[3,0];case 2:return[2]}}))}))},t.prototype.close=function(){return this._timeoutHandle&&(clearTimeout(this._timeoutHandle),this._timeoutHandle=void 0),this.closed=!0,this.size},t}(),et=function(){function t(t,e,r){this.maxChunkRecords=t,this.flushFn=e,this.scheduleSend=r,this.length=0,this.lines=new Array(t)}return t.prototype.add=function(t){0===this.length&&this.scheduleSend(),this.lines[this.length]=t,this.length++,this.length>=this.maxChunkRecords&&this.flush().catch((function(t){}))},t.prototype.flush=function(){var t=this.reset();return t.length>0?this.flushFn(t):Promise.resolve()},t.prototype.reset=function(){var t=this.lines.slice(0,this.length);return this.length=0,t},t}(),rt=function(){function t(t,e,r,n,i){var o=this;this.transport=t,this.closed=!1,this._timeoutHandle=void 0,this.httpPath="/api/v2/write?org="+encodeURIComponent(e)+"&bucket="+encodeURIComponent(r)+"&precision="+n,this.writeOptions=a(a({},E),i),this.currentTime=M[n],this.dateToProtocolTimestamp=N[n],this.writeOptions.defaultTags&&this.useDefaultTags(this.writeOptions.defaultTags),this.sendOptions={method:"POST",headers:a({"content-type":"text/plain; charset=utf-8"},null==i?void 0:i.headers),gzipThreshold:this.writeOptions.gzipThreshold};var s;this.writeBuffer=new et(this.writeOptions.batchSize,(function(t){return o._clearFlushTimeout(),o.sendBatch(t,o.writeOptions.maxRetries+1)}),(function(){o.writeOptions.flushInterval>0&&(o._clearFlushTimeout(),o.closed||(o._timeoutHandle=setTimeout((function(){return o.sendBatch(o.writeBuffer.reset(),o.writeOptions.maxRetries+1).catch((function(t){}))}),o.writeOptions.flushInterval)))})),this.sendBatch=this.sendBatch.bind(this),this.retryStrategy=(s=this.writeOptions,new Z(s)),this.retryBuffer=new tt(this.writeOptions.maxBufferLines,this.sendBatch)}return t.prototype.sendBatch=function(t,e,r){var n=this;void 0===r&&(r=Date.now()+this.writeOptions.maxRetryTime);var i=this,o=i.writeOptions.maxRetries+2-e;if(!this.closed&&t.length>0){if(r<=Date.now()){var s=new Error("Max retry time exceeded.");return q.error("Write to InfluxDB failed (attempt: "+o+").",s),Promise.reject(s)}return new Promise((function(s,u){var a,l={responseStarted:function(t,e){a=e},error:function(n){var a=i.writeOptions.writeFailed.call(i,n,t,o);if(a)a.then(s,u);else{if(!i.closed&&e>1&&(!(n instanceof d)||n.statusCode>=429))return q.warn("Write to InfluxDB failed (attempt: "+o+").",n),i.retryBuffer.addLines(t,e-1,i.retryStrategy.nextDelay(n,o),r),void u(n);q.error("Write to InfluxDB failed.",n),u(n)}},complete:function(){if(204==a||null==a)i.writeOptions.writeSuccess.call(i,t),i.retryStrategy.success(),s();else{var e="204 HTTP response status code expected, but "+a+" returned",r=new d(a,e,void 0,"0");r.message=e,l.error(r)}}};n.transport.send(n.httpPath,t.join("\n"),n.sendOptions,l)}))}return Promise.resolve()},t.prototype._clearFlushTimeout=function(){void 0!==this._timeoutHandle&&(clearTimeout(this._timeoutHandle),this._timeoutHandle=void 0)},t.prototype.writeRecord=function(t){if(this.closed)throw new Error("writeApi: already closed!");this.writeBuffer.add(t)},t.prototype.writeRecords=function(t){if(this.closed)throw new Error("writeApi: already closed!");for(var e=0;e<t.length;e++)this.writeBuffer.add(t[e])},t.prototype.writePoint=function(t){if(this.closed)throw new Error("writeApi: already closed!");var e=t.toLineProtocol(this);e&&this.writeBuffer.add(e)},t.prototype.writePoints=function(t){if(this.closed)throw new Error("writeApi: already closed!");for(var e=0;e<t.length;e++){var r=t[e].toLineProtocol(this);r&&this.writeBuffer.add(r)}},t.prototype.flush=function(t){return l(this,void 0,void 0,(function(){return c(this,(function(e){switch(e.label){case 0:return[4,this.writeBuffer.flush()];case 1:return e.sent(),t?[4,this.retryBuffer.flush()]:[3,3];case 2:return[2,e.sent()];case 3:return[2]}}))}))},t.prototype.close=function(){var t=this;return this.writeBuffer.flush().finally((function(){var e=t.retryBuffer.close();e&&q.error("Retry buffer closed with "+e+" items that were not written to InfluxDB!",null),t.closed=!0}))},t.prototype.dispose=function(){return this._clearFlushTimeout(),this.closed=!0,this.retryBuffer.close()+this.writeBuffer.length},t.prototype.useDefaultTags=function(t){var e=this;return this.defaultTags=void 0,Object.keys(t).forEach((function(r){(e.defaultTags||(e.defaultTags={}))[r]=_.tag(t[r])})),this},t.prototype.convertTime=function(t){return void 0===t?this.currentTime():"string"==typeof t?t.length>0?t:void 0:t instanceof Date?this.dateToProtocolTimestamp(t):String("number"==typeof t?Math.floor(t):t)},t}();function nt(t){var e={};return t.headers.forEach((function(t,r){var n=e[r];void 0===n?e[r]=t:Array.isArray(n)?n.push(t):e[r]=[n,t]})),e}var it=function(){function t(t){this.connectionOptions=t,this.chunkCombiner=e(),this.requestDecorator=function(){},this.defaultHeaders={"content-type":"application/json; charset=utf-8"},this.connectionOptions.token&&(this.defaultHeaders.Authorization="Token "+this.connectionOptions.token),this.url=String(this.connectionOptions.url),this.url.endsWith("/")&&(this.url=this.url.substring(0,this.url.length-1)),this.url.endsWith("/api/v2")&&(this.url=this.url.substring(0,this.url.length-"/api/v2".length),q.warn("Please remove '/api/v2' context path from InfluxDB base url, using "+this.url+" !"))}return t.prototype.send=function(t,e,r,n){var i=this,o=function(t){void 0===t&&(t={});var e=0;return{next:function(r){0===e&&t.next&&null!=r&&t.next(r)},error:function(r){0===e&&(e=1,t.error&&t.error(r))},complete:function(){0===e&&(e=2,t.complete&&t.complete())},responseStarted:function(e,r){t.responseStarted&&t.responseStarted(e,r)}}}(n),s=!1,u=r.signal;if(n&&n.useCancellable){var f=new AbortController;u||(u=f.signal,r=a(a({},r),u)),n.useCancellable({cancel:function(){s=!0,f.abort()},isCancelled:function(){return s||u.aborted}})}this.fetch(t,e,r).then((function(t){return l(i,void 0,void 0,(function(){var e,r,i,s;return c(this,(function(u){switch(u.label){case 0:return(null==n?void 0:n.responseStarted)&&o.responseStarted(nt(t),t.status),t.status>=300?[2,t.text().then((function(e){if(!e){var r=t.headers.get("x-influxdb-error");r&&(e=r)}o.error(new d(t.status,t.statusText,e,t.headers.get("retry-after"),t.headers.get("content-type")))})).catch((function(e){q.warn("Unable to receive error body",e),o.error(new d(t.status,t.statusText,void 0,t.headers.get("retry-after"),t.headers.get("content-type")))}))]:[3,1];case 1:if(!t.body)return[3,6];e=t.body.getReader(),r=void 0,u.label=2;case 2:return[4,e.read()];case 3:r=u.sent(),o.next(r.value),u.label=4;case 4:if(!r.done)return[3,2];u.label=5;case 5:return[3,10];case 6:return t.arrayBuffer?[4,t.arrayBuffer()]:[3,8];case 7:return i=u.sent(),o.next(new Uint8Array(i)),[3,10];case 8:return[4,t.text()];case 9:s=u.sent(),o.next((new TextEncoder).encode(s)),u.label=10;case 10:return[2]}}))}))})).catch((function(t){s||o.error(t)})).finally((function(){return o.complete()}))},t.prototype.request=function(t,e,r,n){var i,o;return l(this,void 0,void 0,(function(){var s,u,a,l,f,h,p;return c(this,(function(c){switch(c.label){case 0:return[4,this.fetch(t,e,r)];case 1:return s=c.sent(),u=s.status,a=s.headers,l=a.get("content-type")||"",n&&n(nt(s),s.status),u>=300?[4,s.text()]:[3,3];case 2:throw(f=c.sent())||(h=a.get("x-influxdb-error"))&&(f=h),new d(u,s.statusText,f,s.headers.get("retry-after"),s.headers.get("content-type"));case 3:return(p=null!==(o=null===(i=r.headers)||void 0===i?void 0:i.accept)&&void 0!==o?o:l).includes("json")?[4,s.json()]:[3,5];case 4:return[2,c.sent()];case 5:return p.includes("text")||p.startsWith("application/csv")?[4,s.text()]:[3,7];case 6:return[2,c.sent()];case 7:return[2]}}))}))},t.prototype.fetch=function(t,e,r){var n=r.method,i=r.headers,o=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]])}return r}(r,["method","headers"]),s=""+this.url+t,u=a({method:n,body:"GET"===n||"HEAD"===n?void 0:"string"==typeof e?e:JSON.stringify(e),headers:a(a({},this.defaultHeaders),i),credentials:"omit"},o);return this.requestDecorator(u,r,s),fetch(s,u)},t}();function ot(t,e){return e.toObject(t)}var st=function(){function t(t,e){var r=this;this.isClosed=!1;try{e({next:function(e){t.next(e)},error:function(e){r.isClosed=!0,t.error(e)},complete:function(){r.isClosed=!0,t.complete()},useCancellable:function(t){r.cancellable=t}})}catch(e){this.isClosed=!0,t.error(e)}}return Object.defineProperty(t.prototype,"closed",{get:function(){return this.isClosed},enumerable:!1,configurable:!0}),t.prototype.unsubscribe=function(){var t;null===(t=this.cancellable)||void 0===t||t.cancel(),this.isClosed=!0},t}();function ut(){}var at=function(){function t(t,e){this.executor=t,this.decorator=e}return t.prototype.subscribe=function(t,e,r){var n=function(t){var e=t.next,r=t.error,n=t.complete;return{next:e?e.bind(t):ut,error:r?r.bind(t):ut,complete:n?n.bind(t):ut}}("object"!=typeof t||null===t?{next:t,error:e,complete:r}:t);return new st(this.decorator(n),this.executor)},t.prototype[K]=function(){return this},t}(),lt={header:!0,delimiter:",",quoteChar:'"',commentPrefix:"#",annotations:["datatype","group","default"]},ct=function(t){return t},ft=function(){function t(t,e){this.transport=t,this.options="string"==typeof e?{org:e}:e}return t.prototype.with=function(e){return new t(this.transport,a(a({},this.options),e))},t.prototype.lines=function(t){return new at(this.createExecutor(t),ct)},t.prototype.rows=function(t){return new at(this.createExecutor(t),(function(t){return O({next:function(e,r){t.next({values:e,tableMeta:r})},error:function(e){t.error(e)},complete:function(){t.complete()}})}))},t.prototype.queryLines=function(t,e){this.createExecutor(t)(e)},t.prototype.queryRows=function(t,e){this.createExecutor(t)(O(e))},t.prototype.collectRows=function(t,e){var r=this;void 0===e&&(e=ot);var n=[];return new Promise((function(i,o){r.queryRows(t,{next:function(t,r){var i=e.call(this,t,r);void 0!==i&&n.push(i)},error:function(t){o(t)},complete:function(){i(n)}})}))},t.prototype.collectLines=function(t){var e=this,r=[];return new Promise((function(n,i){e.queryLines(t,{next:function(t){r.push(t)},error:function(t){i(t)},complete:function(){n(r)}})}))},t.prototype.queryRaw=function(t){var e=this.options,r=e.org,n=e.type,i=e.gzip,o=e.headers;return this.transport.request("/api/v2/query?org="+encodeURIComponent(r),JSON.stringify(this.decorateRequest({query:t.toString(),dialect:lt,type:n})),{method:"POST",headers:a({accept:"text/csv","accept-encoding":i?"gzip":"identity","content-type":"application/json; encoding=utf-8"},o)})},t.prototype.createExecutor=function(t){var e=this,n=this.options,i=n.org,o=n.type,s=n.gzip,u=n.headers;return function(n){e.transport.send("/api/v2/query?org="+encodeURIComponent(i),JSON.stringify(e.decorateRequest({query:t.toString(),dialect:lt,type:o})),{method:"POST",headers:a({"content-type":"application/json; encoding=utf-8","accept-encoding":s?"gzip":"identity"},u)},r(n,e.transport.chunkCombiner))}},t.prototype.decorateRequest=function(t){var e;return"function"==typeof this.options.now&&(t.now=this.options.now()),t.type=null!==(e=this.options.type)&&void 0!==e?e:"flux",t},t}(),ht=function(){function t(t){var e;if("string"==typeof t)this._options={url:t};else{if(null===t||"object"!=typeof t)throw new p("No url or configuration specified!");this._options=t}var r=this._options.url;if("string"!=typeof r)throw new p("No url specified!");r.endsWith("/")&&(this._options.url=r.substring(0,r.length-1)),this.transport=null!==(e=this._options.transport)&&void 0!==e?e:new it(this._options)}return t.prototype.getWriteApi=function(t,e,r,n){return void 0===r&&(r="ns"),new rt(this.transport,t,e,r,null!=n?n:this._options.writeOptions)},t.prototype.getQueryApi=function(t){return new ft(this.transport,t)},t}();return t.AbortError=m,t.DEFAULT_ConnectionOptions={timeout:1e4},t.DEFAULT_RetryDelayStrategyOptions=R,t.DEFAULT_WriteOptions=E,t.FLUX_VALUE=H,t.HttpError=d,t.IllegalArgumentError=p,t.InfluxDB=ht,t.LineSplitter=n,t.Logger=q,t.Point=Q,t.RequestTimedOutError=v,t.canRetryHttpCall=function(t){return!!t&&("function"==typeof t.canRetry?!!t.canRetry():!(!t.code||!y.includes(t.code)))},t.chunksToLines=r,t.consoleLogger=z,t.convertTimeToNanos=k,t.createFluxTableColumn=function(t){var e,r,n=new i;return n.label=String(t.label),n.dataType=t.dataType,n.group=Boolean(t.group),n.defaultValue=null!==(e=t.defaultValue)&&void 0!==e?e:"",n.index=null!==(r=t.index)&&void 0!==r?r:0,n},t.createFluxTableMetaData=T,t.createTextDecoderCombiner=e,t.currentTime=M,t.dateToProtocolTimestamp=N,t.escape=_,t.flux=function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];if(1==t.length&&0===e.length)return $(t[0]);for(var n=new Array(t.length+e.length),i=0,o=0;o<t.length;o++){var s=t[o];if(n[i++]=s,o<e.length){var u=e[o],a=void 0;if(s.endsWith('"')&&o+1<t.length&&t[o+1].startsWith('"'))a=J(u);else if(""===(a=Y(u))&&!W(u))throw new Error("Unsupported parameter literal '"+u+"' at index: "+o+", type: "+typeof u);n[i++]=a}else if(o<t.length-1)throw new Error("Too few parameters supplied!")}return $(n.join(""))},t.fluxBool=function(t){return new V("true"===t||"false"===t?t:(!!t).toString())},t.fluxDateTime=function(t){return new V(function(t){return'time(v: "'+J(t)+'")'}(t))},t.fluxDuration=function(t){return new V('duration(v: "'+J(t)+'")')},t.fluxExpression=$,t.fluxFloat=function(t){return new V(G(t))},t.fluxInteger=function(t){for(var e=G(t),r=0,n=e;r<n.length;r++){if("."===n[r])throw new Error("not a flux integer: "+e)}return new V(e)},t.fluxRegExp=function(t){return new V(X(t))},t.fluxString=function(t){return new V('"'+J(t)+'"')},t.getRetryDelay=g,t.isStatusCodeRetriable=h,t.linesToTables=O,t.newFluxTableColumn=o,t.sanitizeFloat=G,t.serializeDateTimeAsDate=function(){b["dateTime:RFC3339"]=function(t){return""===t?null:new Date(Date.parse(t))}},t.serializeDateTimeAsNumber=function(){b["dateTime:RFC3339"]=function(t){return""===t?null:Date.parse(t)}},t.serializeDateTimeAsString=function(){b["dateTime:RFC3339"]=function(t){return""===t?null:t}},t.setLogger=function(t){var e=U;return U=t,e},t.stringToLines=function(t,e){for(var r=!1,n=0,i=0;i<t.length;){var o=t.charCodeAt(i);if(10===o){if(!r){var s=i>0&&13===t.charCodeAt(i-1)?i-1:i;e.next(t.substring(n,s)),n=i+1}}else 34===o&&(r=!r);i++}n<i&&e.next(t.substring(n,i)),e.complete()},t.symbolObservable=K,t.toFluxValue=Y,t.typeSerializers=b,t.useProcessHrtime=function(t){return!1},Object.defineProperty(t,"__esModule",{value:!0}),t}({});
|
|
16
|
+
var s=function(t,e){return(s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(t,e)};function u(t,e){function r(){this.constructor=t}s(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var a=function(){return(a=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function l(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{a(n.next(t))}catch(t){o(t)}}function u(t){try{a(n.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,u)}a((n=n.apply(t,e||[])).next())}))}function c(t,e){var r,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}}var f=[404,408,425,429,500,502,503,504];function h(t){return f.includes(t)}var p=function(t){function e(r){var n=t.call(this,r)||this;return n.name="IllegalArgumentError",Object.setPrototypeOf(n,e.prototype),n}return u(e,t),e}(Error),d=function(t){function e(r,n,i,o,s,u){var a=t.call(this)||this;if(a.statusCode=r,a.statusMessage=n,a.body=i,a.contentType=s,Object.setPrototypeOf(a,e.prototype),u)a.message=u;else if(i){if(null==s?void 0:s.startsWith("application/json"))try{a.json=JSON.parse(i),a.message=a.json.message,a.code=a.json.code}catch(t){}a.message||(a.message=r+" "+n+" : "+i)}else a.message=r+" "+n;return a.name="HttpError",a.setRetryAfter(o),a}return u(e,t),e.prototype.setRetryAfter=function(t){"string"==typeof t&&/^[0-9]+$/.test(t)?this._retryAfter=parseInt(t):this._retryAfter=0},e.prototype.canRetry=function(){return h(this.statusCode)},e.prototype.retryAfter=function(){return this._retryAfter},e}(Error),y=["ECONNRESET","ENOTFOUND","ESOCKETTIMEDOUT","ETIMEDOUT","ECONNREFUSED","EHOSTUNREACH","EPIPE"];function v(t,e){if(t){var r=void 0;return"function"==typeof t.retryAfter?t.retryAfter():(r=0,e&&e>0?r+Math.round(Math.random()*e):r)}return 0}var g=function(t){function e(){var r=t.call(this)||this;return Object.setPrototypeOf(r,e.prototype),r.name="RequestTimedOutError",r.message="Request timed out",r}return u(e,t),e.prototype.canRetry=function(){return!0},e.prototype.retryAfter=function(){return 0},e}(Error),m=function(t){function e(){var r=t.call(this)||this;return r.name="AbortError",Object.setPrototypeOf(r,e.prototype),r.message="Response aborted",r}return u(e,t),e.prototype.canRetry=function(){return!0},e.prototype.retryAfter=function(){return 0},e}(Error),w=function(t){return t},b={boolean:function(t){return"true"===t},unsignedLong:function(t){return""===t?null:+t},long:function(t){return""===t?null:+t},double:function(t){switch(t){case"":return null;case"+Inf":return Number.POSITIVE_INFINITY;case"-Inf":return Number.NEGATIVE_INFINITY;default:return+t}},string:w,base64Binary:w,duration:function(t){return""===t?null:t},"dateTime:RFC3339":function(t){return""===t?null:t}};var x=function(){function t(t){t.forEach((function(t,e){return t.index=e})),this.columns=t}return t.prototype.column=function(t){for(var e=0;e<this.columns.length;e++){var r=this.columns[e];if(r.label===t)return r}throw new p("Column "+t+" not found!")},t.prototype.toObject=function(t){for(var e,r={},n=0;n<this.columns.length&&n<t.length;n++){var i=t[n],o=this.columns[n];""===i&&o.defaultValue&&(i=o.defaultValue),r[o.label]=(null!==(e=b[o.dataType])&&void 0!==e?e:w)(i)}return r},t}();function T(t){return new x(t)}function O(t){var e,r,i=(new n).withReuse(),s=!0,u=0;return{error:function(e){t.error(e)},next:function(n){if(""===n)s=!0,e=void 0;else{var a=i.splitLine(n),l=i.lastSplitLength;if(s){if(!e){e=new Array(l);for(var c=0;c<l;c++)e[c]=o()}if(a[0].startsWith("#")){if("#datatype"===a[0])for(c=1;c<l;c++)e[c].dataType=a[c];else if("#default"===a[0])for(c=1;c<l;c++)e[c].defaultValue=a[c];else if("#group"===a[0])for(c=1;c<l;c++)e[c].group="t"===a[c][0]}else{""===a[0]?(u=1,e=e.slice(1)):u=0;for(var c=u;c<l;c++)e[c-u].label=a[c];r=T(e),s=!1}}else t.next(a.slice(u,l),r)}},complete:function(){t.complete()},useCancellable:function(e){t.useCancellable&&t.useCancellable(e)}}}var R={retryJitter:200,minRetryDelay:5e3,maxRetryDelay:125e3,exponentialBase:5,randomRetry:!0},S={batchSize:1e3,flushInterval:6e4,writeFailed:function(){},writeSuccess:function(){},maxRetries:5,maxRetryTime:18e4,maxBufferLines:32e3,retryJitter:200,minRetryDelay:5e3,maxRetryDelay:125e3,exponentialBase:2,gzipThreshold:1e3,randomRetry:!0};function E(t,e){return function(r){for(var n="",i=0,o=0;o<r.length;){var s=t.indexOf(r[o]);s>=0&&(n+=r.substring(i,o),n+=e[s],i=o+1),o++}return 0==i?r:(i<r.length&&(n+=r.substring(i,r.length)),n)}}var D,A,C,_={measurement:E(", \n\r\t",["\\,","\\ ","\\n","\\r","\\t"]),quoted:(D='"\\',A=['\\"',"\\\\"],C=E(D,A),function(t){return'"'+C(t)+'"'}),tag:E(", =\n\r\t",["\\,","\\ ","\\=","\\n","\\r","\\t"])};var P=Date.now(),B=0;function L(){var t=Date.now();t!==P?(P=t,B=0):B++;var e=String(B);return String(t)+"000000000".substr(0,6-e.length)+e}function j(){return String(Date.now())+"000000000".substr(0,3)}function F(){return String(Date.now())}function I(){return String(Math.floor(Date.now()/1e3))}var M={s:I,ms:F,us:j,ns:L,seconds:I,millis:F,micros:j,nanos:L},N={s:function(t){return""+Math.floor(t.getTime()/1e3)},ms:function(t){return""+t.getTime()},us:function(t){return t.getTime()+"000"},ns:function(t){return t.getTime()+"000000"}};function k(t){return void 0===t?L():"string"==typeof t?t.length>0?t:void 0:t instanceof Date?t.getTime()+"000000":String("number"==typeof t?Math.floor(t):t)}var z={error:function(t,e){console.error("ERROR: "+t,e||"")},warn:function(t,e){console.warn("WARN: "+t,e||"")}},U=z,q={error:function(t,e){U.error(t,e)},warn:function(t,e){U.warn(t,e)}};var H=Symbol("FLUX_VALUE"),V=function(){function t(t){this.fluxValue=t}return t.prototype.toString=function(){return this.fluxValue},t.prototype[H]=function(){return this.fluxValue},t}();function W(t){return"object"==typeof t&&"function"==typeof t[H]}function J(t){if(null==t)return"";t=t.toString();var e=void 0,r=0;function n(){void 0===e&&(e=t.substring(0,r))}for(;r<t.length;r++){var i=t.charAt(r);switch(i){case"\r":n(),e+="\\r";break;case"\n":n(),e+="\\n";break;case"\t":n(),e+="\\t";break;case'"':case"\\":n(),e=e+"\\"+i;break;case"$":if(r+1<t.length&&"{"===t.charAt(r+1)){n(),r++,e+="\\${";break}null!=e&&(e+=i);break;default:null!=e&&(e+=i)}}return void 0!==e?e:t}function G(t){if("number"==typeof t){if(!isFinite(t))throw new Error("not a flux float: "+t);return t.toString()}for(var e=String(t),r=!1,n=0,i=e;n<i.length;n++){var o=i[n];if("."!==o){if("."!==o&&"-"!==o&&(o<"0"||o>"9"))throw new Error("not a flux float: "+e)}else{if(r)throw new Error("not a flux float: "+e);r=!r}}return e}function X(t){return'regexp.compile(v: "'+J(t)+'")'}function $(t){return new V(String(t))}function Y(t){if(void 0===t)return"";if(null===t)return"null";if("boolean"==typeof t)return t.toString();if("string"==typeof t)return'"'+J(t)+'"';if("number"==typeof t)return G(t);if("object"==typeof t){if("function"==typeof t[H])return t[H]();if(t instanceof Date)return t.toISOString();if(t instanceof RegExp)return X(t);if(Array.isArray(t))return"["+t.map(Y).join(",")+"]"}return Y(t.toString())}var K="function"==typeof Symbol&&Symbol.observable||"@@observable",Q=function(){function t(t){this.tags={},this.fields={},t&&(this.name=t)}return t.prototype.measurement=function(t){return this.name=t,this},t.prototype.tag=function(t,e){return this.tags[t]=e,this},t.prototype.booleanField=function(t,e){return this.fields[t]=e?"T":"F",this},t.prototype.intField=function(t,e){var r;if(r="number"==typeof e?e:parseInt(String(e)),isNaN(r)||r<=-0x8000000000000000||r>=0x8000000000000000)throw new Error("invalid integer value for field '"+t+"': '"+e+"'!");return this.fields[t]=Math.floor(r)+"i",this},t.prototype.uintField=function(t,e){if("number"==typeof e){if(isNaN(e)||e<0||e>Number.MAX_SAFE_INTEGER)throw new Error("uint value for field '"+t+"' out of range: "+e);this.fields[t]=Math.floor(e)+"u"}else{for(var r=String(e),n=0;n<r.length;n++){var i=r.charCodeAt(n);if(i<48||i>57)throw new Error("uint value has an unsupported character at pos "+n+": "+e)}if(r.length>20||20===r.length&&r.localeCompare("18446744073709551615")>0)throw new Error("uint value for field '"+t+"' out of range: "+r);this.fields[t]=r+"u"}return this},t.prototype.floatField=function(t,e){var r;if(r="number"==typeof e?e:parseFloat(e),!isFinite(r))throw new Error("invalid float value for field '"+t+"': "+e);return this.fields[t]=String(r),this},t.prototype.stringField=function(t,e){return null!=e&&("string"!=typeof e&&(e=String(e)),this.fields[t]=_.quoted(e)),this},t.prototype.timestamp=function(t){return this.time=t,this},t.prototype.toLineProtocol=function(t){var e=this;if(this.name){var r="";if(Object.keys(this.fields).sort().forEach((function(t){if(t){var n=e.fields[t];r.length>0&&(r+=","),r+=_.tag(t)+"="+n}})),0!==r.length){var n="",i=t&&t.defaultTags?a(a({},t.defaultTags),this.tags):this.tags;Object.keys(i).sort().forEach((function(t){if(t){var e=i[t];e&&(n+=",",n+=_.tag(t)+"="+_.tag(e))}}));var o=this.time;return o=t&&t.convertTime?t.convertTime(o):k(o),""+_.measurement(this.name)+n+" "+r+(void 0!==o?" "+o:"")}}},t.prototype.toString=function(){var t=this.toLineProtocol(void 0);return t||"invalid point: "+JSON.stringify(this,void 0)},t}(),Z=function(){function t(t){this.options=a(a({},R),t),this.success()}return t.prototype.nextDelay=function(t,e){var r=v(t);if(r&&r>0)return r+Math.round(Math.random()*this.options.retryJitter);if(e&&e>0){if(this.options.randomRetry){for(var n=Math.max(this.options.minRetryDelay,1),i=n*this.options.exponentialBase,o=1;o<e;o++)if(n=i,(i*=this.options.exponentialBase)>=this.options.maxRetryDelay){i=this.options.maxRetryDelay;break}return n+Math.round(Math.random()*(i-n)+Math.random()*this.options.retryJitter)}var s=Math.max(this.options.minRetryDelay,1);for(o=1;o<e;o++)if((s*=this.options.exponentialBase)>=this.options.maxRetryDelay){s=this.options.maxRetryDelay;break}return s+Math.round(Math.random()*this.options.retryJitter)}return this.currentDelay?this.currentDelay=Math.min(Math.max(this.currentDelay*this.options.exponentialBase,1)+Math.round(Math.random()*this.options.retryJitter),this.options.maxRetryDelay):this.currentDelay=this.options.minRetryDelay+Math.round(Math.random()*this.options.retryJitter),this.currentDelay},t.prototype.success=function(){this.currentDelay=void 0},t}();var tt=function(){function t(t,e){this.maxLines=t,this.retryLines=e,this.size=0,this.nextRetryTime=0,this.closed=!1,this._timeoutHandle=void 0}return t.prototype.addLines=function(t,e,r,n){if(!this.closed&&t.length){var i=Date.now()+r;if(n<i&&(r=n-Date.now(),i=n),i>this.nextRetryTime&&(this.nextRetryTime=i),this.first&&this.size+t.length>this.maxLines){var o=this.size,s=.7*o;do{var u=this.first.next;this.size-=this.first.lines.length,this.first.next=void 0,this.first=u,this.first||(this.last=void 0)}while(this.first&&this.size+t.length>s);q.error("RetryBuffer: "+(o-this.size)+" oldest lines removed to keep buffer size under the limit of "+this.maxLines+" lines")}var a={lines:t,retryCount:e,expires:n};this.last?(this.last.next=a,this.last=a):(this.first=a,this.last=a,this.scheduleRetry(r)),this.size+=t.length}},t.prototype.removeLines=function(){if(this.first){var t=this.first;return this.first=this.first.next,t.next=void 0,this.size-=t.lines.length,this.first||(this.last=void 0),t}},t.prototype.scheduleRetry=function(t){var e=this;this._timeoutHandle=setTimeout((function(){var t=e.removeLines();t?e.retryLines(t.lines,t.retryCount,t.expires).then((function(){e.scheduleRetry(1)})).catch((function(t){e.scheduleRetry(e.nextRetryTime-Date.now())})):e._timeoutHandle=void 0}),Math.max(t,0))},t.prototype.flush=function(){return l(this,void 0,void 0,(function(){var t;return c(this,(function(e){switch(e.label){case 0:return(t=this.removeLines())?[4,this.retryLines(t.lines,t.retryCount,t.expires)]:[3,2];case 1:return e.sent(),[3,0];case 2:return[2]}}))}))},t.prototype.close=function(){return this._timeoutHandle&&(clearTimeout(this._timeoutHandle),this._timeoutHandle=void 0),this.closed=!0,this.size},t}(),et=function(){function t(t,e,r){this.maxChunkRecords=t,this.flushFn=e,this.scheduleSend=r,this.length=0,this.lines=new Array(t)}return t.prototype.add=function(t){0===this.length&&this.scheduleSend(),this.lines[this.length]=t,this.length++,this.length>=this.maxChunkRecords&&this.flush().catch((function(t){}))},t.prototype.flush=function(){var t=this.reset();return t.length>0?this.flushFn(t):Promise.resolve()},t.prototype.reset=function(){var t=this.lines.slice(0,this.length);return this.length=0,t},t}(),rt=function(){function t(t,e,r,n,i){var o=this;this.transport=t,this.closed=!1,this._timeoutHandle=void 0,this.httpPath="/api/v2/write?org="+encodeURIComponent(e)+"&bucket="+encodeURIComponent(r)+"&precision="+n,this.writeOptions=a(a({},S),i),this.currentTime=M[n],this.dateToProtocolTimestamp=N[n],this.writeOptions.defaultTags&&this.useDefaultTags(this.writeOptions.defaultTags),this.sendOptions={method:"POST",headers:a({"content-type":"text/plain; charset=utf-8"},null==i?void 0:i.headers),gzipThreshold:this.writeOptions.gzipThreshold};var s;this.writeBuffer=new et(this.writeOptions.batchSize,(function(t){return o._clearFlushTimeout(),o.sendBatch(t,o.writeOptions.maxRetries+1)}),(function(){o.writeOptions.flushInterval>0&&(o._clearFlushTimeout(),o.closed||(o._timeoutHandle=setTimeout((function(){return o.sendBatch(o.writeBuffer.reset(),o.writeOptions.maxRetries+1).catch((function(t){}))}),o.writeOptions.flushInterval)))})),this.sendBatch=this.sendBatch.bind(this),this.retryStrategy=(s=this.writeOptions,new Z(s)),this.retryBuffer=new tt(this.writeOptions.maxBufferLines,this.sendBatch)}return t.prototype.sendBatch=function(t,e,r){var n=this;void 0===r&&(r=Date.now()+this.writeOptions.maxRetryTime);var i=this,o=i.writeOptions.maxRetries+2-e;if(!this.closed&&t.length>0){if(r<=Date.now()){var s=new Error("Max retry time exceeded.");return q.error("Write to InfluxDB failed (attempt: "+o+").",s),Promise.reject(s)}return new Promise((function(s,u){var a,l={responseStarted:function(t,e){a=e},error:function(n){var a=i.writeOptions.writeFailed.call(i,n,t,o);if(a)a.then(s,u);else{if(!i.closed&&e>1&&(!(n instanceof d)||n.statusCode>=429))return q.warn("Write to InfluxDB failed (attempt: "+o+").",n),i.retryBuffer.addLines(t,e-1,i.retryStrategy.nextDelay(n,o),r),void u(n);q.error("Write to InfluxDB failed.",n),u(n)}},complete:function(){if(204==a||null==a)i.writeOptions.writeSuccess.call(i,t),i.retryStrategy.success(),s();else{var e="204 HTTP response status code expected, but "+a+" returned",r=new d(a,e,void 0,"0");r.message=e,l.error(r)}}};n.transport.send(n.httpPath,t.join("\n"),n.sendOptions,l)}))}return Promise.resolve()},t.prototype._clearFlushTimeout=function(){void 0!==this._timeoutHandle&&(clearTimeout(this._timeoutHandle),this._timeoutHandle=void 0)},t.prototype.writeRecord=function(t){if(this.closed)throw new Error("writeApi: already closed!");this.writeBuffer.add(t)},t.prototype.writeRecords=function(t){if(this.closed)throw new Error("writeApi: already closed!");for(var e=0;e<t.length;e++)this.writeBuffer.add(t[e])},t.prototype.writePoint=function(t){if(this.closed)throw new Error("writeApi: already closed!");var e=t.toLineProtocol(this);e&&this.writeBuffer.add(e)},t.prototype.writePoints=function(t){if(this.closed)throw new Error("writeApi: already closed!");for(var e=0;e<t.length;e++){var r=t[e].toLineProtocol(this);r&&this.writeBuffer.add(r)}},t.prototype.flush=function(t){return l(this,void 0,void 0,(function(){return c(this,(function(e){switch(e.label){case 0:return[4,this.writeBuffer.flush()];case 1:return e.sent(),t?[4,this.retryBuffer.flush()]:[3,3];case 2:return[2,e.sent()];case 3:return[2]}}))}))},t.prototype.close=function(){var t=this;return this.writeBuffer.flush().finally((function(){var e=t.retryBuffer.close();e&&q.error("Retry buffer closed with "+e+" items that were not written to InfluxDB!",null),t.closed=!0}))},t.prototype.dispose=function(){return this._clearFlushTimeout(),this.closed=!0,this.retryBuffer.close()+this.writeBuffer.length},t.prototype.useDefaultTags=function(t){var e=this;return this.defaultTags=void 0,Object.keys(t).forEach((function(r){(e.defaultTags||(e.defaultTags={}))[r]=_.tag(t[r])})),this},t.prototype.convertTime=function(t){return void 0===t?this.currentTime():"string"==typeof t?t.length>0?t:void 0:t instanceof Date?this.dateToProtocolTimestamp(t):String("number"==typeof t?Math.floor(t):t)},t}();function nt(t){var e={};return t.headers.forEach((function(t,r){var n=e[r];void 0===n?e[r]=t:Array.isArray(n)?n.push(t):e[r]=[n,t]})),e}var it=function(){function t(t){this.connectionOptions=t,this.chunkCombiner=e(),this.requestDecorator=function(){},this.defaultHeaders={"content-type":"application/json; charset=utf-8"},this.connectionOptions.token&&(this.defaultHeaders.Authorization="Token "+this.connectionOptions.token),this.url=String(this.connectionOptions.url),this.url.endsWith("/")&&(this.url=this.url.substring(0,this.url.length-1)),this.url.endsWith("/api/v2")&&(this.url=this.url.substring(0,this.url.length-"/api/v2".length),q.warn("Please remove '/api/v2' context path from InfluxDB base url, using "+this.url+" !"))}return t.prototype.send=function(t,e,r,n){var i=this,o=function(t){void 0===t&&(t={});var e=0;return{next:function(r){0===e&&t.next&&null!=r&&t.next(r)},error:function(r){0===e&&(e=1,t.error&&t.error(r))},complete:function(){0===e&&(e=2,t.complete&&t.complete())},responseStarted:function(e,r){t.responseStarted&&t.responseStarted(e,r)}}}(n),s=!1,u=r.signal;if(n&&n.useCancellable){var f=new AbortController;u||(u=f.signal,r=a(a({},r),u)),n.useCancellable({cancel:function(){s=!0,f.abort()},isCancelled:function(){return s||u.aborted}})}this.fetch(t,e,r).then((function(t){return l(i,void 0,void 0,(function(){var e,r,i,s;return c(this,(function(u){switch(u.label){case 0:return(null==n?void 0:n.responseStarted)&&o.responseStarted(nt(t),t.status),t.status>=300?[2,t.text().then((function(e){if(!e){var r=t.headers.get("x-influxdb-error");r&&(e=r)}o.error(new d(t.status,t.statusText,e,t.headers.get("retry-after"),t.headers.get("content-type")))})).catch((function(e){q.warn("Unable to receive error body",e),o.error(new d(t.status,t.statusText,void 0,t.headers.get("retry-after"),t.headers.get("content-type")))}))]:[3,1];case 1:if(!t.body)return[3,6];e=t.body.getReader(),r=void 0,u.label=2;case 2:return[4,e.read()];case 3:r=u.sent(),o.next(r.value),u.label=4;case 4:if(!r.done)return[3,2];u.label=5;case 5:return[3,10];case 6:return t.arrayBuffer?[4,t.arrayBuffer()]:[3,8];case 7:return i=u.sent(),o.next(new Uint8Array(i)),[3,10];case 8:return[4,t.text()];case 9:s=u.sent(),o.next((new TextEncoder).encode(s)),u.label=10;case 10:return[2]}}))}))})).catch((function(t){s||o.error(t)})).finally((function(){return o.complete()}))},t.prototype.request=function(t,e,r,n){var i,o;return l(this,void 0,void 0,(function(){var s,u,a,l,f,h,p;return c(this,(function(c){switch(c.label){case 0:return[4,this.fetch(t,e,r)];case 1:return s=c.sent(),u=s.status,a=s.headers,l=a.get("content-type")||"",n&&n(nt(s),s.status),u>=300?[4,s.text()]:[3,3];case 2:throw(f=c.sent())||(h=a.get("x-influxdb-error"))&&(f=h),new d(u,s.statusText,f,s.headers.get("retry-after"),s.headers.get("content-type"));case 3:return(p=null!==(o=null===(i=r.headers)||void 0===i?void 0:i.accept)&&void 0!==o?o:l).includes("json")?[4,s.json()]:[3,5];case 4:return[2,c.sent()];case 5:return p.includes("text")||p.startsWith("application/csv")?[4,s.text()]:[3,7];case 6:return[2,c.sent()];case 7:return[2]}}))}))},t.prototype.fetch=function(t,e,r){var n=r.method,i=r.headers,o=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]])}return r}(r,["method","headers"]),s=""+this.url+t,u=a({method:n,body:"GET"===n||"HEAD"===n?void 0:"string"==typeof e?e:JSON.stringify(e),headers:a(a({},this.defaultHeaders),i),credentials:"omit"},o);return this.requestDecorator(u,r,s),fetch(s,u)},t}();function ot(t,e){return e.toObject(t)}var st=function(){function t(t,e){var r=this;this.isClosed=!1;try{e({next:function(e){t.next(e)},error:function(e){r.isClosed=!0,t.error(e)},complete:function(){r.isClosed=!0,t.complete()},useCancellable:function(t){r.cancellable=t}})}catch(e){this.isClosed=!0,t.error(e)}}return Object.defineProperty(t.prototype,"closed",{get:function(){return this.isClosed},enumerable:!1,configurable:!0}),t.prototype.unsubscribe=function(){var t;null===(t=this.cancellable)||void 0===t||t.cancel(),this.isClosed=!0},t}();function ut(){}var at=function(){function t(t,e){this.executor=t,this.decorator=e}return t.prototype.subscribe=function(t,e,r){var n=function(t){var e=t.next,r=t.error,n=t.complete;return{next:e?e.bind(t):ut,error:r?r.bind(t):ut,complete:n?n.bind(t):ut}}("object"!=typeof t||null===t?{next:t,error:e,complete:r}:t);return new st(this.decorator(n),this.executor)},t.prototype[K]=function(){return this},t}(),lt={header:!0,delimiter:",",quoteChar:'"',commentPrefix:"#",annotations:["datatype","group","default"]},ct=function(t){return t},ft=function(){function t(t,e){this.transport=t,this.options="string"==typeof e?{org:e}:e}return t.prototype.with=function(e){return new t(this.transport,a(a({},this.options),e))},t.prototype.lines=function(t){return new at(this.createExecutor(t),ct)},t.prototype.rows=function(t){return new at(this.createExecutor(t),(function(t){return O({next:function(e,r){t.next({values:e,tableMeta:r})},error:function(e){t.error(e)},complete:function(){t.complete()}})}))},t.prototype.queryLines=function(t,e){this.createExecutor(t)(e)},t.prototype.queryRows=function(t,e){this.createExecutor(t)(O(e))},t.prototype.collectRows=function(t,e){var r=this;void 0===e&&(e=ot);var n=[];return new Promise((function(i,o){r.queryRows(t,{next:function(t,r){var i=e.call(this,t,r);void 0!==i&&n.push(i)},error:function(t){o(t)},complete:function(){i(n)}})}))},t.prototype.collectLines=function(t){var e=this,r=[];return new Promise((function(n,i){e.queryLines(t,{next:function(t){r.push(t)},error:function(t){i(t)},complete:function(){n(r)}})}))},t.prototype.queryRaw=function(t){var e=this.options,r=e.org,n=e.type,i=e.gzip,o=e.headers;return this.transport.request("/api/v2/query?org="+encodeURIComponent(r),JSON.stringify(this.decorateRequest({query:t.toString(),dialect:lt,type:n})),{method:"POST",headers:a({accept:"text/csv","accept-encoding":i?"gzip":"identity","content-type":"application/json; encoding=utf-8"},o)})},t.prototype.createExecutor=function(t){var e=this,n=this.options,i=n.org,o=n.type,s=n.gzip,u=n.headers;return function(n){e.transport.send("/api/v2/query?org="+encodeURIComponent(i),JSON.stringify(e.decorateRequest({query:t.toString(),dialect:lt,type:o})),{method:"POST",headers:a({"content-type":"application/json; encoding=utf-8","accept-encoding":s?"gzip":"identity"},u)},r(n,e.transport.chunkCombiner))}},t.prototype.decorateRequest=function(t){var e;return"function"==typeof this.options.now&&(t.now=this.options.now()),t.type=null!==(e=this.options.type)&&void 0!==e?e:"flux",t},t}(),ht=function(){function t(t){var e;if("string"==typeof t)this._options={url:t};else{if(null===t||"object"!=typeof t)throw new p("No url or configuration specified!");this._options=t}var r=this._options.url;if("string"!=typeof r)throw new p("No url specified!");r.endsWith("/")&&(this._options.url=r.substring(0,r.length-1)),this.transport=null!==(e=this._options.transport)&&void 0!==e?e:new it(this._options)}return t.prototype.getWriteApi=function(t,e,r,n){return void 0===r&&(r="ns"),new rt(this.transport,t,e,r,null!=n?n:this._options.writeOptions)},t.prototype.getQueryApi=function(t){return new ft(this.transport,t)},t}();return t.AbortError=m,t.DEFAULT_ConnectionOptions={timeout:1e4},t.DEFAULT_RetryDelayStrategyOptions=R,t.DEFAULT_WriteOptions=S,t.FLUX_VALUE=H,t.HttpError=d,t.IllegalArgumentError=p,t.InfluxDB=ht,t.LineSplitter=n,t.Logger=q,t.Point=Q,t.RequestTimedOutError=g,t.canRetryHttpCall=function(t){return!!t&&("function"==typeof t.canRetry?!!t.canRetry():!(!t.code||!y.includes(t.code)))},t.chunksToLines=r,t.consoleLogger=z,t.convertTimeToNanos=k,t.createFluxTableColumn=function(t){var e,r,n=new i;return n.label=String(t.label),n.dataType=t.dataType,n.group=Boolean(t.group),n.defaultValue=null!==(e=t.defaultValue)&&void 0!==e?e:"",n.index=null!==(r=t.index)&&void 0!==r?r:0,n},t.createFluxTableMetaData=T,t.createTextDecoderCombiner=e,t.currentTime=M,t.dateToProtocolTimestamp=N,t.escape=_,t.flux=function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];if(1==t.length&&0===e.length)return $(t[0]);for(var n=new Array(t.length+e.length),i=0,o=0;o<t.length;o++){var s=t[o];if(n[i++]=s,o<e.length){var u=e[o],a=void 0;if(s.endsWith('"')&&o+1<t.length&&t[o+1].startsWith('"'))a=J(u);else if(""===(a=Y(u))&&!W(u))throw new Error("Unsupported parameter literal '"+u+"' at index: "+o+", type: "+typeof u);n[i++]=a}else if(o<t.length-1)throw new Error("Too few parameters supplied!")}return $(n.join(""))},t.fluxBool=function(t){return new V("true"===t||"false"===t?t:(!!t).toString())},t.fluxDateTime=function(t){return new V(function(t){return'time(v: "'+J(t)+'")'}(t))},t.fluxDuration=function(t){return new V('duration(v: "'+J(t)+'")')},t.fluxExpression=$,t.fluxFloat=function(t){return new V(G(t))},t.fluxInteger=function(t){for(var e=G(t),r=0,n=e;r<n.length;r++){if("."===n[r])throw new Error("not a flux integer: "+e)}return new V(e)},t.fluxRegExp=function(t){return new V(X(t))},t.fluxString=function(t){return new V('"'+J(t)+'"')},t.getRetryDelay=v,t.isStatusCodeRetriable=h,t.linesToTables=O,t.newFluxTableColumn=o,t.sanitizeFloat=G,t.serializeDateTimeAsDate=function(){b["dateTime:RFC3339"]=function(t){return""===t?null:new Date(Date.parse(t))}},t.serializeDateTimeAsNumber=function(){b["dateTime:RFC3339"]=function(t){return""===t?null:Date.parse(t)}},t.serializeDateTimeAsString=function(){b["dateTime:RFC3339"]=function(t){return""===t?null:t}},t.setLogger=function(t){var e=U;return U=t,e},t.stringToLines=function(t,e){for(var r=!1,n=0,i=0;i<t.length;){var o=t.charCodeAt(i);if(10===o){if(!r){var s=i>0&&13===t.charCodeAt(i-1)?i-1:i;e.next(t.substring(n,s)),n=i+1}}else 34===o&&(r=!r);i++}n<i&&e.next(t.substring(n,i)),e.complete()},t.symbolObservable=K,t.toFluxValue=Y,t.typeSerializers=b,t.useProcessHrtime=function(t){return!1},Object.defineProperty(t,"__esModule",{value:!0}),t}({});
|
|
17
17
|
//# sourceMappingURL=influxdb.min.js.map
|
package/dist/influxdb.min.js.gz
CHANGED
|
Binary file
|