@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/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import{parse as t}from"url";import{request as e}from"http";import{request as r}from"https";import{Buffer as n}from"buffer";import s from"zlib";function i(){const t=new TextDecoder("utf-8");return{concat(t,e){const r=new Uint8Array(t.length+e.length);return r.set(t),r.set(e,t.length),r},copy(t,e,r){const n=new Uint8Array(r-e);return n.set(t.subarray(e,r)),n},toUtf8String:(e,r,n)=>t.decode(e.subarray(r,n))}}function o(t,e){const r=null!=e?e:i();let n,s=!1,o=!1;return{next(e){if(!s)try{!function(e){let i,l=0;for(n?(e=r.concat(n,e),i=n.length):i=0;i<e.length;){const n=e[i];if(10===n){if(!o){const n=i>0&&13===e[i-1]?i-1:i;if(s)return;t.next(r.toUtf8String(e,l,n)),l=i+1}}else 34===n&&(o=!o);i++}n=l<i?r.copy(e,l,i):void 0}(e)}catch(t){this.error(t)}},error(e){s||(s=!0,t.error(e))},complete(){s||(n&&t.next(r.toUtf8String(n,0,n.length)),s=!0,t.complete())},useCancellable(e){if(t.useCancellable){const r=this;t.useCancellable({cancel(){e.cancel(),n=void 0,r.complete()},isCancelled:()=>e.isCancelled()})}}}}class l{constructor(){this._reuse=!1}get reuse(){return this._reuse}set reuse(t){t&&!this.reusedValues&&(this.reusedValues=new Array(10)),this._reuse=t}withReuse(){return this.reuse=!0,this}splitLine(t){if(null==t)return this.lastSplitLength=0,[];let e=0,r=0;const n=this._reuse?this.reusedValues:[];let s=0;for(let i=0;i<t.length;i++){const o=t[i];if(","===o){if(e%2==0){const o=this.getValue(t,r,i,e);this._reuse?n[s++]=o:n.push(o),r=i+1,e=0}}else'"'===o&&e++}const i=this.getValue(t,r,t.length,e);return this._reuse?(n[s]=i,this.lastSplitLength=s+1):(n.push(i),this.lastSplitLength=n.length),n}getValue(t,e,r,n){return e===t.length?"":0===n?t.substring(e,r):2===n?t.substring(e+1,r-1):t.substring(e+1,r-1).replace(/""/gi,'"')}}class a{}function u(){return new a}function c(t){var e,r;const n=new a;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}const h=[404,408,425,429,500,502,503,504];function f(t){return h.includes(t)}class d extends Error{constructor(t){super(t),this.name="IllegalArgumentError",Object.setPrototypeOf(this,d.prototype)}}class p extends Error{constructor(t,e,r,n,s,i){if(super(),this.statusCode=t,this.statusMessage=e,this.body=r,this.contentType=s,Object.setPrototypeOf(this,p.prototype),i)this.message=i;else if(r){if(null==s?void 0:s.startsWith("application/json"))try{this.json=JSON.parse(r),this.message=this.json.message,this.code=this.json.code}catch(t){}this.message||(this.message=`${t} ${e} : ${r}`)}else this.message=`${t} ${e}`;this.name="HttpError",this.setRetryAfter(n)}setRetryAfter(t){"string"==typeof t&&/^[0-9]+$/.test(t)?this._retryAfter=parseInt(t):this._retryAfter=0}canRetry(){return f(this.statusCode)}retryAfter(){return this._retryAfter}}const g=["ECONNRESET","ENOTFOUND","ESOCKETTIMEDOUT","ETIMEDOUT","ECONNREFUSED","EHOSTUNREACH","EPIPE"];function m(t){return!!t&&("function"==typeof t.canRetry?!!t.canRetry():!(!t.code||!g.includes(t.code)))}function y(t,e){if(t){let r;return"function"==typeof t.retryAfter?t.retryAfter():(r=0,e&&e>0?r+Math.round(Math.random()*e):r)}return 0}class w extends Error{constructor(){super(),Object.setPrototypeOf(this,w.prototype),this.name="RequestTimedOutError",this.message="Request timed out"}canRetry(){return!0}retryAfter(){return 0}}class b extends Error{constructor(){super(),this.name="AbortError",Object.setPrototypeOf(this,b.prototype),this.message="Response aborted"}canRetry(){return!0}retryAfter(){return 0}}const x=t=>t,v={boolean:t=>"true"===t,unsignedLong:t=>""===t?null:+t,long:t=>""===t?null:+t,double(t){switch(t){case"":return null;case"+Inf":return Number.POSITIVE_INFINITY;case"-Inf":return Number.NEGATIVE_INFINITY;default:return+t}},string:x,base64Binary:x,duration:t=>""===t?null:t,"dateTime:RFC3339":t=>""===t?null:t};function S(){v["dateTime:RFC3339"]=t=>""===t?null:new Date(Date.parse(t))}function O(){v["dateTime:RFC3339"]=t=>""===t?null:Date.parse(t)}function T(){v["dateTime:RFC3339"]=t=>""===t?null:t}class R{constructor(t){t.forEach((t,e)=>t.index=e),this.columns=t}column(t){for(let e=0;e<this.columns.length;e++){const r=this.columns[e];if(r.label===t)return r}throw new d(`Column ${t} not found!`)}toObject(t){var e;const r={};for(let n=0;n<this.columns.length&&n<t.length;n++){let s=t[n];const i=this.columns[n];""===s&&i.defaultValue&&(s=i.defaultValue),r[i.label]=(null!==(e=v[i.dataType])&&void 0!==e?e:x)(s)}return r}}function E(t){return new R(t)}function C(t){const e=(new l).withReuse();let r,n,s=!0,i=0;return{error(e){t.error(e)},next(o){if(""===o)s=!0,r=void 0;else{const l=e.splitLine(o),a=e.lastSplitLength;if(s){if(!r){r=new Array(a);for(let t=0;t<a;t++)r[t]=u()}if(l[0].startsWith("#")){if("#datatype"===l[0])for(let t=1;t<a;t++)r[t].dataType=l[t];else if("#default"===l[0])for(let t=1;t<a;t++)r[t].defaultValue=l[t];else if("#group"===l[0])for(let t=1;t<a;t++)r[t].group="t"===l[t][0]}else{""===l[0]?(i=1,r=r.slice(1)):i=0;for(let t=i;t<a;t++)r[t-i].label=l[t];n=E(r),s=!1}}else t.next(l.slice(i,a),n)}},complete(){t.complete()},useCancellable(e){t.useCancellable&&t.useCancellable(e)}}}function D(t,e){let r=!1,n=0,s=0;for(;s<t.length;){const i=t.charCodeAt(s);if(10===i){if(!r){const r=s>0&&13===t.charCodeAt(s-1)?s-1:s;e.next(t.substring(n,r)),n=s+1}}else 34===i&&(r=!r);s++}n<s&&e.next(t.substring(n,s)),e.complete()}const j={timeout:1e4},$={retryJitter:200,minRetryDelay:5e3,maxRetryDelay:125e3,exponentialBase:5,randomRetry:!0},_={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 A(t,e){return function(r){let n="",s=0,i=0;for(;i<r.length;){const o=t.indexOf(r[i]);o>=0&&(n+=r.substring(s,i),n+=e[o],s=i+1),i++}return 0==s?r:(s<r.length&&(n+=r.substring(s,r.length)),n)}}const P={measurement:A(", \n\r\t",["\\,","\\ ","\\n","\\r","\\t"]),quoted:function(t,e){const r=A(t,e);return t=>'"'+r(t)+'"'}('"\\',['\\"',"\\\\"]),tag:A(", =\n\r\t",["\\,","\\ ","\\=","\\n","\\r","\\t"])};let B=!1;function M(t){return B=t&&process&&"function"==typeof process.hrtime}M(!0);let L=void 0,I=void 0,N=Date.now(),q=0;function F(){if(B){const t=process.hrtime();let e=Date.now();I?(t[0]=t[0]-I[0],t[1]=t[1]-I[1],t[1]<0&&(t[0]-=1,t[1]+=1e9),e=L+1e3*t[0]+Math.floor(t[1]/1e6)):(I=t,L=e);const r=String(t[1]%1e6);return String(e)+"000000000".substr(0,6-r.length)+r}{const t=Date.now();t!==N?(N=t,q=0):q++;const e=String(q);return String(t)+"000000000".substr(0,6-e.length)+e}}function z(){if(B){const t=process.hrtime(),e=String(Math.trunc(t[1]/1e3)%1e3);return String(Date.now())+"000000000".substr(0,3-e.length)+e}return String(Date.now())+"000000000".substr(0,3)}function U(){return String(Date.now())}function k(){return String(Math.floor(Date.now()/1e3))}const H={s:k,ms:U,us:z,ns:F,seconds:k,millis:U,micros:z,nanos:F},V={s:t=>""+Math.floor(t.getTime()/1e3),ms:t=>""+t.getTime(),us:t=>t.getTime()+"000",ns:t=>t.getTime()+"000000"};function J(t){return void 0===t?F():"string"==typeof t?t.length>0?t:void 0:t instanceof Date?t.getTime()+"000000":String("number"==typeof t?Math.floor(t):t)}const W={error(t,e){console.error("ERROR: "+t,e||"")},warn(t,e){console.warn("WARN: "+t,e||"")}};let Y=W;const G={error(t,e){Y.error(t,e)},warn(t,e){Y.warn(t,e)}};function X(t){const e=Y;return Y=t,e}const Z=Symbol("FLUX_VALUE");class K{constructor(t){this.fluxValue=t}toString(){return this.fluxValue}[Z](){return this.fluxValue}}function Q(t){if(null==t)return"";t=t.toString();let e=void 0,r=0;function n(){void 0===e&&(e=t.substring(0,r))}for(;r<t.length;r++){const s=t.charAt(r);switch(s){case"\r":n(),e+="\\r";break;case"\n":n(),e+="\\n";break;case"\t":n(),e+="\\t";break;case'"':case"\\":n(),e=e+"\\"+s;break;case"$":if(r+1<t.length&&"{"===t.charAt(r+1)){n(),r++,e+="\\${";break}null!=e&&(e+=s);break;default:null!=e&&(e+=s)}}return void 0!==e?e:t}function tt(t){return new K(`"${Q(t)}"`)}function et(t){if("number"==typeof t){if(!isFinite(t))throw new Error("not a flux float: "+t);return t.toString()}const e=String(t);let r=!1;for(const t of e)if("."!==t){if("."!==t&&"-"!==t&&(t<"0"||t>"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 rt(t){return new K(et(t))}function nt(t){const e=et(t);for(const t of e)if("."===t)throw new Error("not a flux integer: "+e);return new K(e)}function st(t){return new K(function(t){return`time(v: "${Q(t)}")`}(t))}function it(t){return new K(`duration(v: "${Q(t)}")`)}function ot(t){return`regexp.compile(v: "${Q(t)}")`}function lt(t){return new K(ot(t))}function at(t){return new K("true"===t||"false"===t?t:(!!t).toString())}function ut(t){return new K(String(t))}function ct(t){if(void 0===t)return"";if(null===t)return"null";if("boolean"==typeof t)return t.toString();if("string"==typeof t)return`"${Q(t)}"`;if("number"==typeof t)return et(t);if("object"==typeof t){if("function"==typeof t[Z])return t[Z]();if(t instanceof Date)return t.toISOString();if(t instanceof RegExp)return ot(t);if(Array.isArray(t))return`[${t.map(ct).join(",")}]`}return ct(t.toString())}function ht(t,...e){if(1==t.length&&0===e.length)return ut(t[0]);const r=new Array(t.length+e.length);let n=0;for(let i=0;i<t.length;i++){const o=t[i];if(r[n++]=o,i<e.length){const l=e[i];let a;if(o.endsWith('"')&&i+1<t.length&&t[i+1].startsWith('"'))a=Q(l);else if(a=ct(l),""===a&&("object"!=typeof(s=l)||"function"!=typeof s[Z]))throw new Error(`Unsupported parameter literal '${l}' at index: ${i}, type: ${typeof l}`);r[n++]=a}else if(i<t.length-1)throw new Error("Too few parameters supplied!")}var s;return ut(r.join(""))}const ft="function"==typeof Symbol&&Symbol.observable||"@@observable";class dt{constructor(t){this.tags={},this.fields={},t&&(this.name=t)}measurement(t){return this.name=t,this}tag(t,e){return this.tags[t]=e,this}booleanField(t,e){return this.fields[t]=e?"T":"F",this}intField(t,e){if("number"!=typeof e){let 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}uintField(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{const r=String(e);for(let t=0;t<r.length;t++){const n=r.charCodeAt(t);if(n<48||n>57)throw new Error(`uint value has an unsupported character at pos ${t}: ${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}floatField(t,e){if("number"!=typeof e){let 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}stringField(t,e){return null!=e&&("string"!=typeof e&&(e=String(e)),this.fields[t]=P.quoted(e)),this}timestamp(t){return this.time=t,this}toLineProtocol(t){if(!this.name)return;let e="";if(Object.keys(this.fields).sort().forEach(t=>{if(t){const r=this.fields[t];e.length>0&&(e+=","),e+=`${P.tag(t)}=${r}`}}),0===e.length)return;let r="";const n=t&&t.defaultTags?Object.assign(Object.assign({},t.defaultTags),this.tags):this.tags;Object.keys(n).sort().forEach(t=>{if(t){const e=n[t];e&&(r+=",",r+=`${P.tag(t)}=${P.tag(e)}`)}});let s=this.time;return s=t&&t.convertTime?t.convertTime(s):J(s),`${P.measurement(this.name)}${r} ${e}${void 0!==s?" "+s:""}`}toString(){const t=this.toLineProtocol(void 0);return t||"invalid point: "+JSON.stringify(this,void 0)}}
1
+ import{parse as t}from"url";import{request as e}from"http";import{request as r}from"https";import{Buffer as n}from"buffer";import s from"zlib";function i(){const t=new TextDecoder("utf-8");return{concat(t,e){const r=new Uint8Array(t.length+e.length);return r.set(t),r.set(e,t.length),r},copy(t,e,r){const n=new Uint8Array(r-e);return n.set(t.subarray(e,r)),n},toUtf8String:(e,r,n)=>t.decode(e.subarray(r,n))}}function o(t,e){const r=null!=e?e:i();let n,s=!1,o=!1;return{next(e){if(!s)try{!function(e){let i,l=0;for(n?(e=r.concat(n,e),i=n.length):i=0;i<e.length;){const n=e[i];if(10===n){if(!o){const n=i>0&&13===e[i-1]?i-1:i;if(s)return;t.next(r.toUtf8String(e,l,n)),l=i+1}}else 34===n&&(o=!o);i++}n=l<i?r.copy(e,l,i):void 0}(e)}catch(t){this.error(t)}},error(e){s||(s=!0,t.error(e))},complete(){s||(n&&t.next(r.toUtf8String(n,0,n.length)),s=!0,t.complete())},useCancellable(e){if(t.useCancellable){const r=this;t.useCancellable({cancel(){e.cancel(),n=void 0,r.complete()},isCancelled:()=>e.isCancelled()})}}}}class l{constructor(){this._reuse=!1}get reuse(){return this._reuse}set reuse(t){t&&!this.reusedValues&&(this.reusedValues=new Array(10)),this._reuse=t}withReuse(){return this.reuse=!0,this}splitLine(t){if(null==t)return this.lastSplitLength=0,[];let e=0,r=0;const n=this._reuse?this.reusedValues:[];let s=0;for(let i=0;i<t.length;i++){const o=t[i];if(","===o){if(e%2==0){const o=this.getValue(t,r,i,e);this._reuse?n[s++]=o:n.push(o),r=i+1,e=0}}else'"'===o&&e++}const i=this.getValue(t,r,t.length,e);return this._reuse?(n[s]=i,this.lastSplitLength=s+1):(n.push(i),this.lastSplitLength=n.length),n}getValue(t,e,r,n){return e===t.length?"":0===n?t.substring(e,r):2===n?t.substring(e+1,r-1):t.substring(e+1,r-1).replace(/""/gi,'"')}}class a{}function u(){return new a}function h(t){var e,r;const n=new a;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}const c=[404,408,425,429,500,502,503,504];function f(t){return c.includes(t)}class d extends Error{constructor(t){super(t),this.name="IllegalArgumentError",Object.setPrototypeOf(this,d.prototype)}}class p extends Error{constructor(t,e,r,n,s,i){if(super(),this.statusCode=t,this.statusMessage=e,this.body=r,this.contentType=s,Object.setPrototypeOf(this,p.prototype),i)this.message=i;else if(r){if(null==s?void 0:s.startsWith("application/json"))try{this.json=JSON.parse(r),this.message=this.json.message,this.code=this.json.code}catch(t){}this.message||(this.message=`${t} ${e} : ${r}`)}else this.message=`${t} ${e}`;this.name="HttpError",this.setRetryAfter(n)}setRetryAfter(t){"string"==typeof t&&/^[0-9]+$/.test(t)?this._retryAfter=parseInt(t):this._retryAfter=0}canRetry(){return f(this.statusCode)}retryAfter(){return this._retryAfter}}const g=["ECONNRESET","ENOTFOUND","ESOCKETTIMEDOUT","ETIMEDOUT","ECONNREFUSED","EHOSTUNREACH","EPIPE"];function m(t){return!!t&&("function"==typeof t.canRetry?!!t.canRetry():!(!t.code||!g.includes(t.code)))}function y(t,e){if(t){let r;return"function"==typeof t.retryAfter?t.retryAfter():(r=0,e&&e>0?r+Math.round(Math.random()*e):r)}return 0}class w extends Error{constructor(){super(),Object.setPrototypeOf(this,w.prototype),this.name="RequestTimedOutError",this.message="Request timed out"}canRetry(){return!0}retryAfter(){return 0}}class b extends Error{constructor(){super(),this.name="AbortError",Object.setPrototypeOf(this,b.prototype),this.message="Response aborted"}canRetry(){return!0}retryAfter(){return 0}}const x=t=>t,v={boolean:t=>"true"===t,unsignedLong:t=>""===t?null:+t,long:t=>""===t?null:+t,double(t){switch(t){case"":return null;case"+Inf":return Number.POSITIVE_INFINITY;case"-Inf":return Number.NEGATIVE_INFINITY;default:return+t}},string:x,base64Binary:x,duration:t=>""===t?null:t,"dateTime:RFC3339":t=>""===t?null:t};function S(){v["dateTime:RFC3339"]=t=>""===t?null:new Date(Date.parse(t))}function O(){v["dateTime:RFC3339"]=t=>""===t?null:Date.parse(t)}function T(){v["dateTime:RFC3339"]=t=>""===t?null:t}class R{constructor(t){t.forEach((t,e)=>t.index=e),this.columns=t}column(t){for(let e=0;e<this.columns.length;e++){const r=this.columns[e];if(r.label===t)return r}throw new d(`Column ${t} not found!`)}toObject(t){var e;const r={};for(let n=0;n<this.columns.length&&n<t.length;n++){let s=t[n];const i=this.columns[n];""===s&&i.defaultValue&&(s=i.defaultValue),r[i.label]=(null!==(e=v[i.dataType])&&void 0!==e?e:x)(s)}return r}}function E(t){return new R(t)}function C(t){const e=(new l).withReuse();let r,n,s=!0,i=0;return{error(e){t.error(e)},next(o){if(""===o)s=!0,r=void 0;else{const l=e.splitLine(o),a=e.lastSplitLength;if(s){if(!r){r=new Array(a);for(let t=0;t<a;t++)r[t]=u()}if(l[0].startsWith("#")){if("#datatype"===l[0])for(let t=1;t<a;t++)r[t].dataType=l[t];else if("#default"===l[0])for(let t=1;t<a;t++)r[t].defaultValue=l[t];else if("#group"===l[0])for(let t=1;t<a;t++)r[t].group="t"===l[t][0]}else{""===l[0]?(i=1,r=r.slice(1)):i=0;for(let t=i;t<a;t++)r[t-i].label=l[t];n=E(r),s=!1}}else t.next(l.slice(i,a),n)}},complete(){t.complete()},useCancellable(e){t.useCancellable&&t.useCancellable(e)}}}function D(t,e){let r=!1,n=0,s=0;for(;s<t.length;){const i=t.charCodeAt(s);if(10===i){if(!r){const r=s>0&&13===t.charCodeAt(s-1)?s-1:s;e.next(t.substring(n,r)),n=s+1}}else 34===i&&(r=!r);s++}n<s&&e.next(t.substring(n,s)),e.complete()}const $={timeout:1e4},j={retryJitter:200,minRetryDelay:5e3,maxRetryDelay:125e3,exponentialBase:5,randomRetry:!0},_={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 A(t,e){return function(r){let n="",s=0,i=0;for(;i<r.length;){const o=t.indexOf(r[i]);o>=0&&(n+=r.substring(s,i),n+=e[o],s=i+1),i++}return 0==s?r:(s<r.length&&(n+=r.substring(s,r.length)),n)}}const P={measurement:A(", \n\r\t",["\\,","\\ ","\\n","\\r","\\t"]),quoted:function(t,e){const r=A(t,e);return t=>'"'+r(t)+'"'}('"\\',['\\"',"\\\\"]),tag:A(", =\n\r\t",["\\,","\\ ","\\=","\\n","\\r","\\t"])};let B=!1;function M(t){return B=t&&process&&"function"==typeof process.hrtime}M(!0);let L=void 0,I=void 0,N=Date.now(),F=0;function q(){if(B){const t=process.hrtime();let e=Date.now();I?(t[0]=t[0]-I[0],t[1]=t[1]-I[1],t[1]<0&&(t[0]-=1,t[1]+=1e9),e=L+1e3*t[0]+Math.floor(t[1]/1e6)):(I=t,L=e);const r=String(t[1]%1e6);return String(e)+"000000000".substr(0,6-r.length)+r}{const t=Date.now();t!==N?(N=t,F=0):F++;const e=String(F);return String(t)+"000000000".substr(0,6-e.length)+e}}function z(){if(B){const t=process.hrtime(),e=String(Math.trunc(t[1]/1e3)%1e3);return String(Date.now())+"000000000".substr(0,3-e.length)+e}return String(Date.now())+"000000000".substr(0,3)}function U(){return String(Date.now())}function k(){return String(Math.floor(Date.now()/1e3))}const H={s:k,ms:U,us:z,ns:q,seconds:k,millis:U,micros:z,nanos:q},V={s:t=>""+Math.floor(t.getTime()/1e3),ms:t=>""+t.getTime(),us:t=>t.getTime()+"000",ns:t=>t.getTime()+"000000"};function J(t){return void 0===t?q():"string"==typeof t?t.length>0?t:void 0:t instanceof Date?t.getTime()+"000000":String("number"==typeof t?Math.floor(t):t)}const W={error(t,e){console.error("ERROR: "+t,e||"")},warn(t,e){console.warn("WARN: "+t,e||"")}};let Y=W;const G={error(t,e){Y.error(t,e)},warn(t,e){Y.warn(t,e)}};function X(t){const e=Y;return Y=t,e}const Z=Symbol("FLUX_VALUE");class K{constructor(t){this.fluxValue=t}toString(){return this.fluxValue}[Z](){return this.fluxValue}}function Q(t){if(null==t)return"";t=t.toString();let e=void 0,r=0;function n(){void 0===e&&(e=t.substring(0,r))}for(;r<t.length;r++){const s=t.charAt(r);switch(s){case"\r":n(),e+="\\r";break;case"\n":n(),e+="\\n";break;case"\t":n(),e+="\\t";break;case'"':case"\\":n(),e=e+"\\"+s;break;case"$":if(r+1<t.length&&"{"===t.charAt(r+1)){n(),r++,e+="\\${";break}null!=e&&(e+=s);break;default:null!=e&&(e+=s)}}return void 0!==e?e:t}function tt(t){return new K(`"${Q(t)}"`)}function et(t){if("number"==typeof t){if(!isFinite(t))throw new Error("not a flux float: "+t);return t.toString()}const e=String(t);let r=!1;for(const t of e)if("."!==t){if("."!==t&&"-"!==t&&(t<"0"||t>"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 rt(t){return new K(et(t))}function nt(t){const e=et(t);for(const t of e)if("."===t)throw new Error("not a flux integer: "+e);return new K(e)}function st(t){return new K(function(t){return`time(v: "${Q(t)}")`}(t))}function it(t){return new K(`duration(v: "${Q(t)}")`)}function ot(t){return`regexp.compile(v: "${Q(t)}")`}function lt(t){return new K(ot(t))}function at(t){return new K("true"===t||"false"===t?t:(!!t).toString())}function ut(t){return new K(String(t))}function ht(t){if(void 0===t)return"";if(null===t)return"null";if("boolean"==typeof t)return t.toString();if("string"==typeof t)return`"${Q(t)}"`;if("number"==typeof t)return et(t);if("object"==typeof t){if("function"==typeof t[Z])return t[Z]();if(t instanceof Date)return t.toISOString();if(t instanceof RegExp)return ot(t);if(Array.isArray(t))return`[${t.map(ht).join(",")}]`}return ht(t.toString())}function ct(t,...e){if(1==t.length&&0===e.length)return ut(t[0]);const r=new Array(t.length+e.length);let n=0;for(let i=0;i<t.length;i++){const o=t[i];if(r[n++]=o,i<e.length){const l=e[i];let a;if(o.endsWith('"')&&i+1<t.length&&t[i+1].startsWith('"'))a=Q(l);else if(a=ht(l),""===a&&("object"!=typeof(s=l)||"function"!=typeof s[Z]))throw new Error(`Unsupported parameter literal '${l}' at index: ${i}, type: ${typeof l}`);r[n++]=a}else if(i<t.length-1)throw new Error("Too few parameters supplied!")}var s;return ut(r.join(""))}const ft="function"==typeof Symbol&&Symbol.observable||"@@observable";class dt{constructor(t){this.tags={},this.fields={},t&&(this.name=t)}measurement(t){return this.name=t,this}tag(t,e){return this.tags[t]=e,this}booleanField(t,e){return this.fields[t]=e?"T":"F",this}intField(t,e){let 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}uintField(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{const r=String(e);for(let t=0;t<r.length;t++){const n=r.charCodeAt(t);if(n<48||n>57)throw new Error(`uint value has an unsupported character at pos ${t}: ${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}floatField(t,e){let 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}stringField(t,e){return null!=e&&("string"!=typeof e&&(e=String(e)),this.fields[t]=P.quoted(e)),this}timestamp(t){return this.time=t,this}toLineProtocol(t){if(!this.name)return;let e="";if(Object.keys(this.fields).sort().forEach(t=>{if(t){const r=this.fields[t];e.length>0&&(e+=","),e+=`${P.tag(t)}=${r}`}}),0===e.length)return;let r="";const n=t&&t.defaultTags?Object.assign(Object.assign({},t.defaultTags),this.tags):this.tags;Object.keys(n).sort().forEach(t=>{if(t){const e=n[t];e&&(r+=",",r+=`${P.tag(t)}=${P.tag(e)}`)}});let s=this.time;return s=t&&t.convertTime?t.convertTime(s):J(s),`${P.measurement(this.name)}${r} ${e}${void 0!==s?" "+s:""}`}toString(){const t=this.toLineProtocol(void 0);return t||"invalid point: "+JSON.stringify(this,void 0)}}
2
2
  /*! *****************************************************************************
3
3
  Copyright (c) Microsoft Corporation.
4
4
 
@@ -12,5 +12,5 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
12
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
13
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
14
  PERFORMANCE OF THIS SOFTWARE.
15
- ***************************************************************************** */function pt(t,e,r,n){return new(r||(r=Promise))((function(s,i){function o(t){try{a(n.next(t))}catch(t){i(t)}}function l(t){try{a(n.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?s(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,l)}a((n=n.apply(t,e||[])).next())}))}class gt{constructor(t){this.options=Object.assign(Object.assign({},$),t),this.success()}nextDelay(t,e){const r=y(t);if(r&&r>0)return r+Math.round(Math.random()*this.options.retryJitter);if(e&&e>0){if(this.options.randomRetry){let t=Math.max(this.options.minRetryDelay,1),r=t*this.options.exponentialBase;for(let n=1;n<e;n++)if(t=r,r*=this.options.exponentialBase,r>=this.options.maxRetryDelay){r=this.options.maxRetryDelay;break}return t+Math.round(Math.random()*(r-t)+Math.random()*this.options.retryJitter)}let t=Math.max(this.options.minRetryDelay,1);for(let r=1;r<e;r++)if(t*=this.options.exponentialBase,t>=this.options.maxRetryDelay){t=this.options.maxRetryDelay;break}return t+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}success(){this.currentDelay=void 0}}class mt{constructor(t,e){this.maxLines=t,this.retryLines=e,this.size=0,this.nextRetryTime=0,this.closed=!1,this._timeoutHandle=void 0}addLines(t,e,r,n){if(this.closed)return;if(!t.length)return;let s=Date.now()+r;if(n<s&&(r=n-Date.now(),s=n),s>this.nextRetryTime&&(this.nextRetryTime=s),this.first&&this.size+t.length>this.maxLines){const e=this.size,r=.7*e;do{const t=this.first.next;this.size-=this.first.lines.length,this.first.next=void 0,this.first=t,this.first||(this.last=void 0)}while(this.first&&this.size+t.length>r);G.error(`RetryBuffer: ${e-this.size} oldest lines removed to keep buffer size under the limit of ${this.maxLines} lines`)}const i={lines:t,retryCount:e,expires:n};this.last?(this.last.next=i,this.last=i):(this.first=i,this.last=i,this.scheduleRetry(r)),this.size+=t.length}removeLines(){if(this.first){const 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}}scheduleRetry(t){this._timeoutHandle=setTimeout(()=>{const t=this.removeLines();t?this.retryLines(t.lines,t.retryCount,t.expires).then(()=>{this.scheduleRetry(1)}).catch(t=>{this.scheduleRetry(this.nextRetryTime-Date.now())}):this._timeoutHandle=void 0},Math.max(t,0))}flush(){return pt(this,void 0,void 0,(function*(){let t;for(;t=this.removeLines();)yield this.retryLines(t.lines,t.retryCount,t.expires)}))}close(){return this._timeoutHandle&&(clearTimeout(this._timeoutHandle),this._timeoutHandle=void 0),this.closed=!0,this.size}}class yt{constructor(t,e,r){this.maxChunkRecords=t,this.flushFn=e,this.scheduleSend=r,this.length=0,this.lines=new Array(t)}add(t){0===this.length&&this.scheduleSend(),this.lines[this.length]=t,this.length++,this.length>=this.maxChunkRecords&&this.flush().catch(t=>{})}flush(){const t=this.reset();return t.length>0?this.flushFn(t):Promise.resolve()}reset(){const t=this.lines.slice(0,this.length);return this.length=0,t}}class wt{constructor(t,e,r,n,s){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=Object.assign(Object.assign({},_),s),this.currentTime=H[n],this.dateToProtocolTimestamp=V[n],this.writeOptions.defaultTags&&this.useDefaultTags(this.writeOptions.defaultTags),this.sendOptions={method:"POST",headers:Object.assign({"content-type":"text/plain; charset=utf-8"},null==s?void 0:s.headers),gzipThreshold:this.writeOptions.gzipThreshold};var i;this.writeBuffer=new yt(this.writeOptions.batchSize,t=>(this._clearFlushTimeout(),this.sendBatch(t,this.writeOptions.maxRetries+1)),()=>{this.writeOptions.flushInterval>0&&(this._clearFlushTimeout(),this.closed||(this._timeoutHandle=setTimeout(()=>this.sendBatch(this.writeBuffer.reset(),this.writeOptions.maxRetries+1).catch(t=>{}),this.writeOptions.flushInterval)))}),this.sendBatch=this.sendBatch.bind(this),this.retryStrategy=(i=this.writeOptions,new gt(i)),this.retryBuffer=new mt(this.writeOptions.maxBufferLines,this.sendBatch)}sendBatch(t,e,r=Date.now()+this.writeOptions.maxRetryTime){const n=this,s=n.writeOptions.maxRetries+2-e;if(!this.closed&&t.length>0){if(r<=Date.now()){const t=new Error("Max retry time exceeded.");return G.error(`Write to InfluxDB failed (attempt: ${s}).`,t),Promise.reject(t)}return new Promise((i,o)=>{let l;const a={responseStarted(t,e){l=e},error(l){const a=n.writeOptions.writeFailed.call(n,l,t,s);if(a)a.then(i,o);else{if(!n.closed&&e>1&&(!(l instanceof p)||l.statusCode>=429))return G.warn(`Write to InfluxDB failed (attempt: ${s}).`,l),n.retryBuffer.addLines(t,e-1,n.retryStrategy.nextDelay(l,s),r),void o(l);G.error("Write to InfluxDB failed.",l),o(l)}},complete(){if(204==l||null==l)n.writeOptions.writeSuccess.call(n,t),n.retryStrategy.success(),i();else{const t=`204 HTTP response status code expected, but ${l} returned`,e=new p(l,t,void 0,"0");e.message=t,a.error(e)}}};this.transport.send(this.httpPath,t.join("\n"),this.sendOptions,a)})}return Promise.resolve()}_clearFlushTimeout(){void 0!==this._timeoutHandle&&(clearTimeout(this._timeoutHandle),this._timeoutHandle=void 0)}writeRecord(t){if(this.closed)throw new Error("writeApi: already closed!");this.writeBuffer.add(t)}writeRecords(t){if(this.closed)throw new Error("writeApi: already closed!");for(let e=0;e<t.length;e++)this.writeBuffer.add(t[e])}writePoint(t){if(this.closed)throw new Error("writeApi: already closed!");const e=t.toLineProtocol(this);e&&this.writeBuffer.add(e)}writePoints(t){if(this.closed)throw new Error("writeApi: already closed!");for(let e=0;e<t.length;e++){const r=t[e].toLineProtocol(this);r&&this.writeBuffer.add(r)}}flush(t){return pt(this,void 0,void 0,(function*(){if(yield this.writeBuffer.flush(),t)return yield this.retryBuffer.flush()}))}close(){return this.writeBuffer.flush().finally(()=>{const t=this.retryBuffer.close();t&&G.error(`Retry buffer closed with ${t} items that were not written to InfluxDB!`,null),this.closed=!0})}dispose(){return this._clearFlushTimeout(),this.closed=!0,this.retryBuffer.close()+this.writeBuffer.length}useDefaultTags(t){return this.defaultTags=void 0,Object.keys(t).forEach(e=>{(this.defaultTags||(this.defaultTags={}))[e]=P.tag(t[e])}),this}convertTime(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)}}const bt={concat:(t,e)=>n.concat([t,e]),toUtf8String:(t,e,r)=>t.toString("utf-8",e,r),copy(t,e,r){const s=n.allocUnsafe(r-e);return t.copy(s,0,e,r),s}};const xt={flush:s.constants.Z_SYNC_FLUSH,finishFlush:s.constants.Z_SYNC_FLUSH},vt=n.allocUnsafe(0);class St{constructor(){this.cancelled=!1}cancel(){this.cancelled=!0}isCancelled(){return this.cancelled}}class Ot{constructor(n){var s,i,o,l,a,u,c;this.connectionOptions=n,this.chunkCombiner=bt;const h=t(n.url);if(this.defaultOptions=Object.assign(Object.assign(Object.assign(Object.assign({},j),n),n.transportOptions),{port:h.port,protocol:h.protocol,hostname:h.hostname}),this.contextPath=null!==(s=h.path)&&void 0!==s?s:"",this.contextPath.endsWith("/")&&(this.contextPath=this.contextPath.substring(0,this.contextPath.length-1)),"/api/v2"==this.contextPath&&(G.warn(`Please remove '/api/v2' context path from InfluxDB base url, using ${h.protocol}//${h.hostname}:${h.port} !`),this.contextPath=""),"http:"===h.protocol)this.requestApi=null!==(l=null===(o=null===(i=this.defaultOptions["follow-redirects"])||void 0===i?void 0:i.http)||void 0===o?void 0:o.request)&&void 0!==l?l:e;else{if("https:"!==h.protocol)throw new Error(`Unsupported protocol "${h.protocol} in URL: "${n.url}"`);this.requestApi=null!==(c=null===(u=null===(a=this.defaultOptions["follow-redirects"])||void 0===a?void 0:a.https)||void 0===u?void 0:u.request)&&void 0!==c?c:r}}send(t,e,r,n){const s=new St;n&&n.useCancellable&&n.useCancellable(s),this.createRequestMessage(t,e,r).then(t=>{this._request(t,s,n)},t=>(null==n?void 0:n.error)&&n.error(t))}request(t,e,r,s){e?"string"!=typeof e&&(e=JSON.stringify(e)):e="";let i,o=vt;return new Promise((l,a)=>{this.send(t,e,r,{responseStarted(t,e){s&&s(t,e),i=String(t["content-type"])},next:t=>{o=n.concat([o,t])},complete:()=>{var t,e;const n=null!==(e=null===(t=r.headers)||void 0===t?void 0:t.accept)&&void 0!==e?e:i;try{n.includes("json")?l(JSON.parse(o.toString("utf8"))):n.includes("text")||n.startsWith("application/csv")?l(o.toString("utf8")):l(o)}catch(t){a(t)}},error:t=>{a(t)}})})}createRequestMessage(t,e,r){const i=n.from(e,"utf-8"),o={"content-type":"application/json; charset=utf-8","User-Agent":"influxdb-client-js/1.18.0"};this.connectionOptions.token&&(o.authorization="Token "+this.connectionOptions.token);let l=Promise.resolve(i);const a=Object.assign(Object.assign({},this.defaultOptions),{path:this.contextPath+t,method:r.method,headers:Object.assign(Object.assign({},o),r.headers)});return void 0!==r.gzipThreshold&&r.gzipThreshold<i.length&&(l=l.then(t=>new Promise((e,r)=>{s.gzip(t,(t,n)=>t?r(t):(a.headers["content-encoding"]="gzip",e(n)))}))),l.then(t=>(a.body=t,a.headers["content-length"]=t.length,a))}_request(t,e,r){const n=function(t={}){let e=0;return{next:r=>{0===e&&t.next&&null!=r&&t.next(r)},error:r=>{0===e&&(e=1,t.error&&t.error(r))},complete:()=>{0===e&&(e=2,t.complete&&t.complete())},responseStarted:(e,r)=>{t.responseStarted&&t.responseStarted(e,r)}}}(r);if(e.isCancelled())return void n.complete();const i=this.requestApi(t,t=>{var r;if(e.isCancelled())return t.resume(),void n.complete();t.on("aborted",()=>{n.error(new b)}),n.responseStarted(t.headers,t.statusCode);const i=null!==(r=t.statusCode)&&void 0!==r?r:600;let o;if("gzip"===t.headers["content-encoding"]?(o=s.createGunzip(xt),t.pipe(o)):o=t,o.on("error",n.error),i>=300){let e="";const r=String(t.headers["content-type"]).startsWith("application/json");o.on("data",n=>{e+=n.toString(),!r&&e.length>1e3&&(e=e.slice(0,1e3),t.resume())}),o.on("end",()=>{""===e&&t.headers["x-influxdb-error"]&&(e=t.headers["x-influxdb-error"].toString()),n.error(new p(i,t.statusMessage,e,t.headers["retry-after"],t.headers["content-type"]))})}else o.on("data",r=>{e.isCancelled()?t.resume():n.next(r)}),o.on("end",n.complete)});"function"==typeof i.setTimeout&&i.setTimeout(t.timeout),i.on("timeout",()=>{n.error(new w)}),i.on("error",t=>{n.error(t)}),i.on("close",n.complete),t.body&&i.write(t.body),i.end()}}function Tt(t,e){return e.toObject(t)}class Rt{constructor(t,e){this.isClosed=!1;try{e({next:e=>{t.next(e)},error:e=>{this.isClosed=!0,t.error(e)},complete:()=>{this.isClosed=!0,t.complete()},useCancellable:t=>{this.cancellable=t}})}catch(e){this.isClosed=!0,t.error(e)}}get closed(){return this.isClosed}unsubscribe(){var t;null===(t=this.cancellable)||void 0===t||t.cancel(),this.isClosed=!0}}function Et(){}class Ct{constructor(t,e){this.executor=t,this.decorator=e}subscribe(t,e,r){const n=function(t){const{next:e,error:r,complete:n}=t;return{next:e?e.bind(t):Et,error:r?r.bind(t):Et,complete:n?n.bind(t):Et}}("object"!=typeof t||null===t?{next:t,error:e,complete:r}:t);return new Rt(this.decorator(n),this.executor)}[ft](){return this}}const Dt={header:!0,delimiter:",",quoteChar:'"',commentPrefix:"#",annotations:["datatype","group","default"]},jt=t=>t;class $t{constructor(t,e){this.transport=t,this.options="string"==typeof e?{org:e}:e}with(t){return new $t(this.transport,Object.assign(Object.assign({},this.options),t))}lines(t){return new Ct(this.createExecutor(t),jt)}rows(t){return new Ct(this.createExecutor(t),t=>C({next(e,r){t.next({values:e,tableMeta:r})},error(e){t.error(e)},complete(){t.complete()}}))}queryLines(t,e){this.createExecutor(t)(e)}queryRows(t,e){this.createExecutor(t)(C(e))}collectRows(t,e=Tt){const r=[];return new Promise((n,s)=>{this.queryRows(t,{next(t,n){const s=e.call(this,t,n);void 0!==s&&r.push(s)},error(t){s(t)},complete(){n(r)}})})}collectLines(t){const e=[];return new Promise((r,n)=>{this.queryLines(t,{next(t){e.push(t)},error(t){n(t)},complete(){r(e)}})})}queryRaw(t){const{org:e,type:r,gzip:n,headers:s}=this.options;return this.transport.request("/api/v2/query?org="+encodeURIComponent(e),JSON.stringify(this.decorateRequest({query:t.toString(),dialect:Dt,type:r})),{method:"POST",headers:Object.assign({accept:"text/csv","accept-encoding":n?"gzip":"identity","content-type":"application/json; encoding=utf-8"},s)})}createExecutor(t){const{org:e,type:r,gzip:n,headers:s}=this.options;return i=>{this.transport.send("/api/v2/query?org="+encodeURIComponent(e),JSON.stringify(this.decorateRequest({query:t.toString(),dialect:Dt,type:r})),{method:"POST",headers:Object.assign({"content-type":"application/json; encoding=utf-8","accept-encoding":n?"gzip":"identity"},s)},o(i,this.transport.chunkCombiner))}}decorateRequest(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}}class _t{constructor(t){var e;if("string"==typeof t)this._options={url:t};else{if(null===t||"object"!=typeof t)throw new d("No url or configuration specified!");this._options=t}const r=this._options.url;if("string"!=typeof r)throw new d("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 Ot(this._options)}getWriteApi(t,e,r="ns",n){return new wt(this.transport,t,e,r,null!=n?n:this._options.writeOptions)}getQueryApi(t){return new $t(this.transport,t)}}export{b as AbortError,j as DEFAULT_ConnectionOptions,$ as DEFAULT_RetryDelayStrategyOptions,_ as DEFAULT_WriteOptions,Z as FLUX_VALUE,p as HttpError,d as IllegalArgumentError,_t as InfluxDB,l as LineSplitter,G as Logger,dt as Point,w as RequestTimedOutError,m as canRetryHttpCall,o as chunksToLines,W as consoleLogger,J as convertTimeToNanos,c as createFluxTableColumn,E as createFluxTableMetaData,i as createTextDecoderCombiner,H as currentTime,V as dateToProtocolTimestamp,P as escape,ht as flux,at as fluxBool,st as fluxDateTime,it as fluxDuration,ut as fluxExpression,rt as fluxFloat,nt as fluxInteger,lt as fluxRegExp,tt as fluxString,y as getRetryDelay,f as isStatusCodeRetriable,C as linesToTables,u as newFluxTableColumn,et as sanitizeFloat,S as serializeDateTimeAsDate,O as serializeDateTimeAsNumber,T as serializeDateTimeAsString,X as setLogger,D as stringToLines,ft as symbolObservable,ct as toFluxValue,v as typeSerializers,M as useProcessHrtime};
15
+ ***************************************************************************** */function pt(t,e,r,n){return new(r||(r=Promise))((function(s,i){function o(t){try{a(n.next(t))}catch(t){i(t)}}function l(t){try{a(n.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?s(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,l)}a((n=n.apply(t,e||[])).next())}))}class gt{constructor(t){this.options=Object.assign(Object.assign({},j),t),this.success()}nextDelay(t,e){const r=y(t);if(r&&r>0)return r+Math.round(Math.random()*this.options.retryJitter);if(e&&e>0){if(this.options.randomRetry){let t=Math.max(this.options.minRetryDelay,1),r=t*this.options.exponentialBase;for(let n=1;n<e;n++)if(t=r,r*=this.options.exponentialBase,r>=this.options.maxRetryDelay){r=this.options.maxRetryDelay;break}return t+Math.round(Math.random()*(r-t)+Math.random()*this.options.retryJitter)}let t=Math.max(this.options.minRetryDelay,1);for(let r=1;r<e;r++)if(t*=this.options.exponentialBase,t>=this.options.maxRetryDelay){t=this.options.maxRetryDelay;break}return t+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}success(){this.currentDelay=void 0}}class mt{constructor(t,e){this.maxLines=t,this.retryLines=e,this.size=0,this.nextRetryTime=0,this.closed=!1,this._timeoutHandle=void 0}addLines(t,e,r,n){if(this.closed)return;if(!t.length)return;let s=Date.now()+r;if(n<s&&(r=n-Date.now(),s=n),s>this.nextRetryTime&&(this.nextRetryTime=s),this.first&&this.size+t.length>this.maxLines){const e=this.size,r=.7*e;do{const t=this.first.next;this.size-=this.first.lines.length,this.first.next=void 0,this.first=t,this.first||(this.last=void 0)}while(this.first&&this.size+t.length>r);G.error(`RetryBuffer: ${e-this.size} oldest lines removed to keep buffer size under the limit of ${this.maxLines} lines`)}const i={lines:t,retryCount:e,expires:n};this.last?(this.last.next=i,this.last=i):(this.first=i,this.last=i,this.scheduleRetry(r)),this.size+=t.length}removeLines(){if(this.first){const 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}}scheduleRetry(t){this._timeoutHandle=setTimeout(()=>{const t=this.removeLines();t?this.retryLines(t.lines,t.retryCount,t.expires).then(()=>{this.scheduleRetry(1)}).catch(t=>{this.scheduleRetry(this.nextRetryTime-Date.now())}):this._timeoutHandle=void 0},Math.max(t,0))}flush(){return pt(this,void 0,void 0,(function*(){let t;for(;t=this.removeLines();)yield this.retryLines(t.lines,t.retryCount,t.expires)}))}close(){return this._timeoutHandle&&(clearTimeout(this._timeoutHandle),this._timeoutHandle=void 0),this.closed=!0,this.size}}class yt{constructor(t,e,r){this.maxChunkRecords=t,this.flushFn=e,this.scheduleSend=r,this.length=0,this.lines=new Array(t)}add(t){0===this.length&&this.scheduleSend(),this.lines[this.length]=t,this.length++,this.length>=this.maxChunkRecords&&this.flush().catch(t=>{})}flush(){const t=this.reset();return t.length>0?this.flushFn(t):Promise.resolve()}reset(){const t=this.lines.slice(0,this.length);return this.length=0,t}}class wt{constructor(t,e,r,n,s){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=Object.assign(Object.assign({},_),s),this.currentTime=H[n],this.dateToProtocolTimestamp=V[n],this.writeOptions.defaultTags&&this.useDefaultTags(this.writeOptions.defaultTags),this.sendOptions={method:"POST",headers:Object.assign({"content-type":"text/plain; charset=utf-8"},null==s?void 0:s.headers),gzipThreshold:this.writeOptions.gzipThreshold};var i;this.writeBuffer=new yt(this.writeOptions.batchSize,t=>(this._clearFlushTimeout(),this.sendBatch(t,this.writeOptions.maxRetries+1)),()=>{this.writeOptions.flushInterval>0&&(this._clearFlushTimeout(),this.closed||(this._timeoutHandle=setTimeout(()=>this.sendBatch(this.writeBuffer.reset(),this.writeOptions.maxRetries+1).catch(t=>{}),this.writeOptions.flushInterval)))}),this.sendBatch=this.sendBatch.bind(this),this.retryStrategy=(i=this.writeOptions,new gt(i)),this.retryBuffer=new mt(this.writeOptions.maxBufferLines,this.sendBatch)}sendBatch(t,e,r=Date.now()+this.writeOptions.maxRetryTime){const n=this,s=n.writeOptions.maxRetries+2-e;if(!this.closed&&t.length>0){if(r<=Date.now()){const t=new Error("Max retry time exceeded.");return G.error(`Write to InfluxDB failed (attempt: ${s}).`,t),Promise.reject(t)}return new Promise((i,o)=>{let l;const a={responseStarted(t,e){l=e},error(l){const a=n.writeOptions.writeFailed.call(n,l,t,s);if(a)a.then(i,o);else{if(!n.closed&&e>1&&(!(l instanceof p)||l.statusCode>=429))return G.warn(`Write to InfluxDB failed (attempt: ${s}).`,l),n.retryBuffer.addLines(t,e-1,n.retryStrategy.nextDelay(l,s),r),void o(l);G.error("Write to InfluxDB failed.",l),o(l)}},complete(){if(204==l||null==l)n.writeOptions.writeSuccess.call(n,t),n.retryStrategy.success(),i();else{const t=`204 HTTP response status code expected, but ${l} returned`,e=new p(l,t,void 0,"0");e.message=t,a.error(e)}}};this.transport.send(this.httpPath,t.join("\n"),this.sendOptions,a)})}return Promise.resolve()}_clearFlushTimeout(){void 0!==this._timeoutHandle&&(clearTimeout(this._timeoutHandle),this._timeoutHandle=void 0)}writeRecord(t){if(this.closed)throw new Error("writeApi: already closed!");this.writeBuffer.add(t)}writeRecords(t){if(this.closed)throw new Error("writeApi: already closed!");for(let e=0;e<t.length;e++)this.writeBuffer.add(t[e])}writePoint(t){if(this.closed)throw new Error("writeApi: already closed!");const e=t.toLineProtocol(this);e&&this.writeBuffer.add(e)}writePoints(t){if(this.closed)throw new Error("writeApi: already closed!");for(let e=0;e<t.length;e++){const r=t[e].toLineProtocol(this);r&&this.writeBuffer.add(r)}}flush(t){return pt(this,void 0,void 0,(function*(){if(yield this.writeBuffer.flush(),t)return yield this.retryBuffer.flush()}))}close(){return this.writeBuffer.flush().finally(()=>{const t=this.retryBuffer.close();t&&G.error(`Retry buffer closed with ${t} items that were not written to InfluxDB!`,null),this.closed=!0})}dispose(){return this._clearFlushTimeout(),this.closed=!0,this.retryBuffer.close()+this.writeBuffer.length}useDefaultTags(t){return this.defaultTags=void 0,Object.keys(t).forEach(e=>{(this.defaultTags||(this.defaultTags={}))[e]=P.tag(t[e])}),this}convertTime(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)}}const bt={concat:(t,e)=>n.concat([t,e]),toUtf8String:(t,e,r)=>t.toString("utf-8",e,r),copy(t,e,r){const s=n.allocUnsafe(r-e);return t.copy(s,0,e,r),s}};const xt={flush:s.constants.Z_SYNC_FLUSH,finishFlush:s.constants.Z_SYNC_FLUSH},vt=n.allocUnsafe(0);class St{constructor(){this.cancelled=!1}cancel(){this.cancelled=!0}isCancelled(){return this.cancelled}}class Ot{constructor(n){var s,i,o,l,a,u,h;this.connectionOptions=n,this.chunkCombiner=bt;const c=t(n.url);if(this.defaultOptions=Object.assign(Object.assign(Object.assign(Object.assign({},$),n),n.transportOptions),{port:c.port,protocol:c.protocol,hostname:c.hostname}),this.contextPath=null!==(s=c.path)&&void 0!==s?s:"",this.contextPath.endsWith("/")&&(this.contextPath=this.contextPath.substring(0,this.contextPath.length-1)),"/api/v2"==this.contextPath&&(G.warn(`Please remove '/api/v2' context path from InfluxDB base url, using ${c.protocol}//${c.hostname}:${c.port} !`),this.contextPath=""),"http:"===c.protocol)this.requestApi=null!==(l=null===(o=null===(i=this.defaultOptions["follow-redirects"])||void 0===i?void 0:i.http)||void 0===o?void 0:o.request)&&void 0!==l?l:e;else{if("https:"!==c.protocol)throw new Error(`Unsupported protocol "${c.protocol} in URL: "${n.url}"`);this.requestApi=null!==(h=null===(u=null===(a=this.defaultOptions["follow-redirects"])||void 0===a?void 0:a.https)||void 0===u?void 0:u.request)&&void 0!==h?h:r}}send(t,e,r,n){const s=new St;n&&n.useCancellable&&n.useCancellable(s),this.createRequestMessage(t,e,r).then(t=>{this._request(t,s,n)},t=>(null==n?void 0:n.error)&&n.error(t))}request(t,e,r,s){e?"string"!=typeof e&&(e=JSON.stringify(e)):e="";let i,o=vt;return new Promise((l,a)=>{this.send(t,e,r,{responseStarted(t,e){s&&s(t,e),i=String(t["content-type"])},next:t=>{o=n.concat([o,t])},complete:()=>{var t,e;const n=null!==(e=null===(t=r.headers)||void 0===t?void 0:t.accept)&&void 0!==e?e:i;try{n.includes("json")?l(JSON.parse(o.toString("utf8"))):n.includes("text")||n.startsWith("application/csv")?l(o.toString("utf8")):l(o)}catch(t){a(t)}},error:t=>{a(t)}})})}createRequestMessage(t,e,r){const i=n.from(e,"utf-8"),o={"content-type":"application/json; charset=utf-8","User-Agent":"influxdb-client-js/1.19.0"};this.connectionOptions.token&&(o.authorization="Token "+this.connectionOptions.token);let l=Promise.resolve(i);const a=Object.assign(Object.assign({},this.defaultOptions),{path:this.contextPath+t,method:r.method,headers:Object.assign(Object.assign({},o),r.headers)});return void 0!==r.gzipThreshold&&r.gzipThreshold<i.length&&(l=l.then(t=>new Promise((e,r)=>{s.gzip(t,(t,n)=>t?r(t):(a.headers["content-encoding"]="gzip",e(n)))}))),l.then(t=>(a.body=t,a.headers["content-length"]=t.length,a))}_request(t,e,r){const n=function(t={}){let e=0;return{next:r=>{0===e&&t.next&&null!=r&&t.next(r)},error:r=>{0===e&&(e=1,t.error&&t.error(r))},complete:()=>{0===e&&(e=2,t.complete&&t.complete())},responseStarted:(e,r)=>{t.responseStarted&&t.responseStarted(e,r)}}}(r);if(e.isCancelled())return void n.complete();const i=this.requestApi(t,t=>{var r;if(e.isCancelled())return t.resume(),void n.complete();t.on("aborted",()=>{n.error(new b)}),n.responseStarted(t.headers,t.statusCode);const i=null!==(r=t.statusCode)&&void 0!==r?r:600;let o;if("gzip"===t.headers["content-encoding"]?(o=s.createGunzip(xt),t.pipe(o)):o=t,o.on("error",n.error),i>=300){let e="";const r=String(t.headers["content-type"]).startsWith("application/json");o.on("data",n=>{e+=n.toString(),!r&&e.length>1e3&&(e=e.slice(0,1e3),t.resume())}),o.on("end",()=>{""===e&&t.headers["x-influxdb-error"]&&(e=t.headers["x-influxdb-error"].toString()),n.error(new p(i,t.statusMessage,e,t.headers["retry-after"],t.headers["content-type"]))})}else o.on("data",r=>{e.isCancelled()?t.resume():n.next(r)}),o.on("end",n.complete)});"function"==typeof i.setTimeout&&i.setTimeout(t.timeout),i.on("timeout",()=>{n.error(new w)}),i.on("error",t=>{n.error(t)}),i.on("close",n.complete),t.body&&i.write(t.body),i.end()}}function Tt(t,e){return e.toObject(t)}class Rt{constructor(t,e){this.isClosed=!1;try{e({next:e=>{t.next(e)},error:e=>{this.isClosed=!0,t.error(e)},complete:()=>{this.isClosed=!0,t.complete()},useCancellable:t=>{this.cancellable=t}})}catch(e){this.isClosed=!0,t.error(e)}}get closed(){return this.isClosed}unsubscribe(){var t;null===(t=this.cancellable)||void 0===t||t.cancel(),this.isClosed=!0}}function Et(){}class Ct{constructor(t,e){this.executor=t,this.decorator=e}subscribe(t,e,r){const n=function(t){const{next:e,error:r,complete:n}=t;return{next:e?e.bind(t):Et,error:r?r.bind(t):Et,complete:n?n.bind(t):Et}}("object"!=typeof t||null===t?{next:t,error:e,complete:r}:t);return new Rt(this.decorator(n),this.executor)}[ft](){return this}}const Dt={header:!0,delimiter:",",quoteChar:'"',commentPrefix:"#",annotations:["datatype","group","default"]},$t=t=>t;class jt{constructor(t,e){this.transport=t,this.options="string"==typeof e?{org:e}:e}with(t){return new jt(this.transport,Object.assign(Object.assign({},this.options),t))}lines(t){return new Ct(this.createExecutor(t),$t)}rows(t){return new Ct(this.createExecutor(t),t=>C({next(e,r){t.next({values:e,tableMeta:r})},error(e){t.error(e)},complete(){t.complete()}}))}queryLines(t,e){this.createExecutor(t)(e)}queryRows(t,e){this.createExecutor(t)(C(e))}collectRows(t,e=Tt){const r=[];return new Promise((n,s)=>{this.queryRows(t,{next(t,n){const s=e.call(this,t,n);void 0!==s&&r.push(s)},error(t){s(t)},complete(){n(r)}})})}collectLines(t){const e=[];return new Promise((r,n)=>{this.queryLines(t,{next(t){e.push(t)},error(t){n(t)},complete(){r(e)}})})}queryRaw(t){const{org:e,type:r,gzip:n,headers:s}=this.options;return this.transport.request("/api/v2/query?org="+encodeURIComponent(e),JSON.stringify(this.decorateRequest({query:t.toString(),dialect:Dt,type:r})),{method:"POST",headers:Object.assign({accept:"text/csv","accept-encoding":n?"gzip":"identity","content-type":"application/json; encoding=utf-8"},s)})}createExecutor(t){const{org:e,type:r,gzip:n,headers:s}=this.options;return i=>{this.transport.send("/api/v2/query?org="+encodeURIComponent(e),JSON.stringify(this.decorateRequest({query:t.toString(),dialect:Dt,type:r})),{method:"POST",headers:Object.assign({"content-type":"application/json; encoding=utf-8","accept-encoding":n?"gzip":"identity"},s)},o(i,this.transport.chunkCombiner))}}decorateRequest(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}}class _t{constructor(t){var e;if("string"==typeof t)this._options={url:t};else{if(null===t||"object"!=typeof t)throw new d("No url or configuration specified!");this._options=t}const r=this._options.url;if("string"!=typeof r)throw new d("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 Ot(this._options)}getWriteApi(t,e,r="ns",n){return new wt(this.transport,t,e,r,null!=n?n:this._options.writeOptions)}getQueryApi(t){return new jt(this.transport,t)}}export{b as AbortError,$ as DEFAULT_ConnectionOptions,j as DEFAULT_RetryDelayStrategyOptions,_ as DEFAULT_WriteOptions,Z as FLUX_VALUE,p as HttpError,d as IllegalArgumentError,_t as InfluxDB,l as LineSplitter,G as Logger,dt as Point,w as RequestTimedOutError,m as canRetryHttpCall,o as chunksToLines,W as consoleLogger,J as convertTimeToNanos,h as createFluxTableColumn,E as createFluxTableMetaData,i as createTextDecoderCombiner,H as currentTime,V as dateToProtocolTimestamp,P as escape,ct as flux,at as fluxBool,st as fluxDateTime,it as fluxDuration,ut as fluxExpression,rt as fluxFloat,nt as fluxInteger,lt as fluxRegExp,tt as fluxString,y as getRetryDelay,f as isStatusCodeRetriable,C as linesToTables,u as newFluxTableColumn,et as sanitizeFloat,S as serializeDateTimeAsDate,O as serializeDateTimeAsNumber,T as serializeDateTimeAsString,X as setLogger,D as stringToLines,ft as symbolObservable,ht as toFluxValue,v as typeSerializers,M as useProcessHrtime};
16
16
  //# sourceMappingURL=index.mjs.map
package/dist/index.mjs.gz CHANGED
Binary file