@influxdata/influxdb-client-browser 1.30.0 → 1.31.0-nightly.2887
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.browser.js +5 -5
- package/dist/index.browser.js.gz +0 -0
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.mjs +5 -5
- package/dist/index.browser.mjs.gz +0 -0
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.d.ts +22 -2
- package/dist/index.js +5 -5
- package/dist/index.js.gz +0 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/index.mjs.gz +0 -0
- package/dist/index.mjs.map +1 -1
- package/dist/influxdb.js +5 -5
- package/dist/influxdb.js.gz +0 -0
- package/dist/influxdb.js.map +1 -1
- package/package.json +3 -3
package/dist/index.browser.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
\r `,["\\,","\\ ","\\n","\\r","\\t"]),quoted
|
|
3
|
-
\r `,["\\,","\\ ","\\=","\\n","\\r","\\t"])};var
|
|
4
|
-
`:n(),e+="\\n";break;case" ":n(),e+="\\t";break;case'"':case"\\":n(),e=e+"\\"+i;break;case"$":if(t+1<r.length&&r.charAt(t+1)==="{"){n(),t++,e+="\\${";break}e!=null&&(e+=i);break;default:e!=null&&(e+=i)}}return e!==void 0?e:r}function Wt(r){return new h(`"${C(r)}"`)}function be(r){let e=Number(r);if(!isFinite(e)){if(typeof r=="number")return`float(v: "${e}")`;throw new Error(`not a flux float: ${r}`)}let t=e.toString(),n=!1;for(let i of t)if(!(i>="0"&&i<="9"||i=="-")){if(i==="."){n=!0;continue}return`float(v: "${t}")`}return n?t:t+".0"}function kt(r){return new h(be(r))}function xe(r){let e=String(r),t=e.startsWith("-"),n=t?e.substring(1):e;if(n.length===0||n.length>19)throw new Error(`not a flux integer: ${e}`);for(let i of n)if(i<"0"||i>"9")throw new Error(`not a flux integer: ${e}`);if(n.length===19){if(t&&n>"9223372036854775808")throw new Error(`flux integer out of bounds: ${e}`);if(!t&&n>"9223372036854775807")throw new Error(`flux integer out of bounds: ${e}`)}return e}function Nt(r){return new h(xe(r))}function Be(r){return`time(v: "${C(r)}")`}function jt(r){return new h(Be(r))}function Qt(r){return new h(`duration(v: "${C(r)}")`)}function Te(r){return r instanceof RegExp?r.toString():new RegExp(r).toString()}function qt(r){return new h(Te(r))}function Jt(r){return r==="true"||r==="false"?new h(r):new h((!!r).toString())}function ye(r){return new h(String(r))}function Q(r){if(r===void 0)return"";if(r===null)return"null";if(typeof r=="boolean")return r.toString();if(typeof r=="string")return`"${C(r)}"`;if(typeof r=="number")return Number.isSafeInteger(r)?xe(r):be(r);if(typeof r=="object"){if(typeof r[B]=="function")return r[B]();if(r instanceof Date)return r.toISOString();if(r instanceof RegExp)return Te(r);if(Array.isArray(r))return`[${r.map(Q).join(",")}]`}else if(typeof r=="bigint")return`${r}.0`;return Q(r.toString())}function Xt(r,...e){if(r.length==1&&e.length===0)return ye(r[0]);let t=new Array(r.length+e.length),n=0;for(let i=0;i<r.length;i++){let s=r[i];if(t[n++]=s,i<e.length){let l=e[i],o;if(s.endsWith('"')&&i+1<r.length&&r[i+1].startsWith('"'))o=C(l);else if(o=Q(l),o===""&&!Ie(l))throw new Error(`Unsupported parameter literal '${l}' at index: ${i}, type: ${typeof l}`);t[n++]=o}else if(i<r.length-1)throw new Error("Too few parameters supplied!")}return ye(t.join(""))}var we=class{constructor(e){this.tags={};this.fields={};e&&(this.name=e)}measurement(e){return this.name=e,this}tag(e,t){return this.tags[e]=t,this}booleanField(e,t){return this.fields[e]=t?"T":"F",this}intField(e,t){let n;if(typeof t=="number"?n=t:n=parseInt(String(t)),isNaN(n)||n<=-9223372036854776e3||n>=9223372036854776e3)throw new Error(`invalid integer value for field '${e}': '${t}'!`);return this.fields[e]=`${Math.floor(n)}i`,this}uintField(e,t){if(typeof t=="number"){if(isNaN(t)||t<0||t>Number.MAX_SAFE_INTEGER)throw new Error(`uint value for field '${e}' out of range: ${t}`);this.fields[e]=`${Math.floor(t)}u`}else{let n=String(t);for(let i=0;i<n.length;i++){let s=n.charCodeAt(i);if(s<48||s>57)throw new Error(`uint value has an unsupported character at pos ${i}: ${t}`)}if(n.length>20||n.length===20&&n.localeCompare("18446744073709551615")>0)throw new Error(`uint value for field '${e}' out of range: ${n}`);this.fields[e]=`${n}u`}return this}floatField(e,t){let n;if(typeof t=="number"?n=t:n=parseFloat(t),!isFinite(n))throw new Error(`invalid float value for field '${e}': ${t}`);return this.fields[e]=String(n),this}stringField(e,t){return t!=null&&(typeof t!="string"&&(t=String(t)),this.fields[e]=T.quoted(t)),this}timestamp(e){return this.time=e,this}toLineProtocol(e){if(!this.name)return;let t="";if(Object.keys(this.fields).sort().forEach(l=>{if(l){let o=this.fields[l];t.length>0&&(t+=","),t+=`${T.tag(l)}=${o}`}}),t.length===0)return;let n="",i=e&&e.defaultTags?c(c({},e.defaultTags),this.tags):this.tags;Object.keys(i).sort().forEach(l=>{if(l){let o=i[l];o&&(n+=",",n+=`${T.tag(l)}=${T.tag(o)}`)}});let s=this.time;return e&&e.convertTime?s=e.convertTime(s):s=ge(s),`${T.measurement(this.name)}${n} ${t}${s!==void 0?" "+s:""}`}toString(){let e=this.toLineProtocol(void 0);return e||`invalid point: ${JSON.stringify(this,void 0)}`}};var q=class{constructor(e){this.options=c(c({},ae),e),this.success()}nextDelay(e,t){let n=ie(e);if(n&&n>0)return n+Math.round(Math.random()*this.options.retryJitter);if(t&&t>0){if(this.options.randomRetry){let s=Math.max(this.options.minRetryDelay,1),l=s*this.options.exponentialBase;for(let o=1;o<t;o++)if(s=l,l=l*this.options.exponentialBase,l>=this.options.maxRetryDelay){l=this.options.maxRetryDelay;break}return s+Math.round(Math.random()*(l-s)+Math.random()*this.options.retryJitter)}let i=Math.max(this.options.minRetryDelay,1);for(let s=1;s<t;s++)if(i=i*this.options.exponentialBase,i>=this.options.maxRetryDelay){i=this.options.maxRetryDelay;break}return i+Math.round(Math.random()*this.options.retryJitter)}else 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);return this.currentDelay}success(){this.currentDelay=void 0}};function Re(r){return new q(r)}function _e(r){let e,t=r,n=r;for(;n.next;)n.next.expires<t.expires&&(e=n,t=n.next),n=n.next;return[t,e]}var S=class{constructor(e,t,n=()=>{}){this.maxLines=e;this.retryLines=t;this.onShrink=n;this.size=0;this.closed=!1;this._timeoutHandle=void 0}addLines(e,t,n,i){if(this.closed||!e.length)return;let s=Date.now()+n;if(i<s&&(s=i),this.first&&this.size+e.length>this.maxLines){let u=this.size,f=u*.7;do{let[d,b]=_e(this.first);this.size-=d.lines.length,b?b.next=d.next:(this.first=d.next,this.first&&this.scheduleRetry(this.first.retryTime-Date.now())),d.next=void 0,this.onShrink(d)}while(this.first&&this.size+e.length>f);p.error(`RetryBuffer: ${u-this.size} oldest lines removed to keep buffer size under the limit of ${this.maxLines} lines.`)}let l={lines:e,retryCount:t,retryTime:s,expires:i},o=this.first,a;for(;;){if(!o||o.retryTime>s){l.next=o,a?a.next=l:(this.first=l,this.scheduleRetry(s-Date.now()));break}a=o,o=o.next}this.size+=e.length}removeLines(){if(this.first){let e=this.first;return this.first=this.first.next,e.next=void 0,this.size-=e.lines.length,e}}scheduleRetry(e){this._timeoutHandle&&clearTimeout(this._timeoutHandle),this._timeoutHandle=setTimeout(()=>{let t=this.removeLines();t?this.retryLines(t.lines,t.retryCount,t.expires).finally(()=>{this.first&&this.scheduleRetry(this.first.retryTime-Date.now())}):this._timeoutHandle=void 0},Math.max(e,0))}flush(){return y(this,null,function*(){let e;for(;e=this.removeLines();)yield this.retryLines(e.lines,e.retryCount,e.expires)})}close(){return this._timeoutHandle&&(clearTimeout(this._timeoutHandle),this._timeoutHandle=void 0),this.closed=!0,this.size}};function J(r){let e=r.length;for(let t=0;t<r.length;t++){let n=r.charCodeAt(t);n<128||(n>=128&&n<=2047?e++:n>=2048&&n<=65535?n>=55296&&n<=57343?e++:e+=2:e+=3)}return e}var X=class{constructor(e,t,n,i){this.maxChunkRecords=e;this.maxBatchBytes=t;this.flushFn=n;this.scheduleSend=i;this.length=0;this.bytes=-1;this.lines=new Array(e)}add(e){let t=J(e);this.length===0?this.scheduleSend():this.bytes+t+1>=this.maxBatchBytes&&this.flush().catch(n=>{}),this.lines[this.length]=e,this.length++,this.bytes+=t+1,(this.length>=this.maxChunkRecords||this.bytes>=this.maxBatchBytes)&&this.flush().catch(n=>{})}flush(){let e=this.reset();return e.length>0?this.flushFn(e):Promise.resolve()}reset(){let e=this.lines.slice(0,this.length);return this.length=0,this.bytes=-1,e}},O=class{constructor(e,t,n,i,s){this.transport=e;this.closed=!1;this._timeoutHandle=void 0;this.path=`/api/v2/write?org=${encodeURIComponent(t)}&bucket=${encodeURIComponent(n)}&precision=${i}`,s!=null&&s.consistency&&(this.path+=`&consistency=${encodeURIComponent(s.consistency)}`),this.writeOptions=c(c({},le),s),this.currentTime=pe[i],this.dateToProtocolTimestamp=he[i],this.writeOptions.defaultTags&&this.useDefaultTags(this.writeOptions.defaultTags),this.sendOptions={method:"POST",headers:c({"content-type":"text/plain; charset=utf-8"},s==null?void 0:s.headers),gzipThreshold:this.writeOptions.gzipThreshold};let l=()=>{this.writeOptions.flushInterval>0&&(this._clearFlushTimeout(),this.closed||(this._timeoutHandle=setTimeout(()=>this.sendBatch(this.writeBuffer.reset(),this.writeOptions.maxRetries).catch(o=>{}),this.writeOptions.flushInterval)))};this.writeBuffer=new X(this.writeOptions.batchSize,this.writeOptions.maxBatchBytes,o=>(this._clearFlushTimeout(),this.sendBatch(o,this.writeOptions.maxRetries)),l),this.sendBatch=this.sendBatch.bind(this),this.retryStrategy=Re(this.writeOptions),this.retryBuffer=new S(this.writeOptions.maxBufferLines,this.sendBatch,this.writeOptions.writeRetrySkipped)}sendBatch(e,t,n=Date.now()+this.writeOptions.maxRetryTime){let i=this,s=i.writeOptions.maxRetries+1-t;if(!this.closed&&e.length>0){if(n<=Date.now()){let l=new Error("Max retry time exceeded."),o=i.writeOptions.writeFailed.call(i,l,e,s,n);return o||(p.error(`Write to InfluxDB failed (attempt: ${s}).`,l),Promise.reject(l))}return new Promise((l,o)=>{let a,u={responseStarted(f,d){a=d},error(f){let d=i.writeOptions.writeFailed.call(i,f,e,s,n);if(d){d.then(l,o);return}if(f instanceof m&&f.json&&typeof f.json.error=="string"&&f.json.error.includes("hinted handoff queue not empty")){p.warn("Write to InfluxDB returns: "+f.json.error),a=204,u.complete();return}if(!i.closed&&t>0&&(!(f instanceof m)||f.statusCode>=429)){p.warn(`Write to InfluxDB failed (attempt: ${s}).`,f),i.retryBuffer.addLines(e,t-1,i.retryStrategy.nextDelay(f,s),n),o(f);return}p.error("Write to InfluxDB failed.",f),o(f)},complete(){if(a==204||a==null)i.writeOptions.writeSuccess.call(i,e),i.retryStrategy.success(),l();else{let f=`204 HTTP response status code expected, but ${a} returned`,d=new m(a,f,void 0,"0");d.message=f,u.error(d)}}};this.transport.send(this.path,e.join(`
|
|
5
|
-
`),this.sendOptions,
|
|
1
|
+
var Ae=Object.defineProperty;var F=Object.getOwnPropertySymbols;var te=Object.prototype.hasOwnProperty,re=Object.prototype.propertyIsEnumerable;var ee=(t,e,r)=>e in t?Ae(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,d=(t,e)=>{for(var r in e||(e={}))te.call(e,r)&&ee(t,r,e[r]);if(F)for(var r of F(e))re.call(e,r)&&ee(t,r,e[r]);return t};var ne=(t,e)=>{var r={};for(var n in t)te.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&F)for(var n of F(t))e.indexOf(n)<0&&re.call(t,n)&&(r[n]=t[n]);return r};var x=(t,e,r)=>new Promise((n,i)=>{var s=f=>{try{l(r.next(f))}catch(c){i(c)}},o=f=>{try{l(r.throw(f))}catch(c){i(c)}},l=f=>f.done?n(f.value):Promise.resolve(f.value).then(s,o);l((r=r.apply(t,e)).next())});function L(){let t=new TextDecoder("utf-8");return{concat(e,r){let n=new Uint8Array(e.length+r.length);return n.set(e),n.set(r,e.length),n},copy(e,r,n){let i=new Uint8Array(n-r);return i.set(e.subarray(r,n)),i},toUtf8String(e,r,n){return t.decode(e.subarray(r,n))}}}function R(t,e){let r=e!=null?e:L(),n,i=!1,s=!1,o=!1,l;function f(a){let u,m=0;for(n?(u=a.length===0?0:n.length,a=r.concat(n,a)):u=0;u<a.length;){let p=a[u];if(p===10){if(!s){let P=u>0&&a[u-1]===13?u-1:u;if(i)return;if(o=t.next(r.toUtf8String(a,m,P))===!1,m=u+1,o)break}}else p===34&&(s=!s);u++}if(m<a.length?n=r.copy(a,m,a.length):n=void 0,o){if(t.useResume){t.useResume(()=>{o=!1,f(new Uint8Array(0))});return}c.error(new Error("Unable to pause, useResume is not configured!")),o=!1}l&&(l(),l=void 0)}let c={next(a){if(!i)try{return f(a),!o}catch(u){this.error(u)}return!0},error(a){i||(i=!0,t.error(a))},complete(){i||(n&&t.next(r.toUtf8String(n,0,n.length)),i=!0,t.complete())}};return t.useCancellable&&(c.useCancellable=a=>{t.useCancellable&&t.useCancellable({cancel(){a.cancel(),n=void 0,c.complete()},isCancelled(){return a.isCancelled()}})}),t.useResume&&(c.useResume=a=>{l=a}),c}var $=class{constructor(){this._reuse=!1}get reuse(){return this._reuse}set reuse(e){e&&!this.reusedValues&&(this.reusedValues=new Array(10)),this._reuse=e}withReuse(){return this.reuse=!0,this}splitLine(e){if(e==null)return this.lastSplitLength=0,[];let r=0,n=0,i=this._reuse?this.reusedValues:[],s=0;for(let l=0;l<e.length;l++){let f=e[l];if(f===","){if(r%2===0){let c=this.getValue(e,n,l,r);this._reuse?i[s++]=c:i.push(c),n=l+1,r=0}}else f==='"'&&r++}let o=this.getValue(e,n,e.length,r);return this._reuse?(i[s]=o,this.lastSplitLength=s+1):(i.push(o),this.lastSplitLength=i.length),i}getValue(e,r,n,i){return r===e.length?"":i===0?e.substring(r,n):i===2?e.substring(r+1,n-1):e.substring(r+1,n-1).replace(/""/gi,'"')}};var H=t=>t,C={boolean:t=>t===""?null:t==="true",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:H,base64Binary:H,duration:t=>t===""?null:t,"dateTime:RFC3339":t=>t===""?null:t},I=class{get(e){var n;let r=e[this.index];return(r===""||r===void 0)&&this.defaultValue&&(r=this.defaultValue),((n=C[this.dataType])!=null?n:H)(r)}},ie=Object.freeze({label:"",dataType:"",group:!1,defaultValue:"",index:Number.MAX_SAFE_INTEGER,get:()=>{}});function se(){return new I}function Qe(t){var r,n;let e=new I;return e.label=String(t.label),e.dataType=t.dataType,e.group=Boolean(t.group),e.defaultValue=(r=t.defaultValue)!=null?r:"",e.index=(n=t.index)!=null?n:0,e}var Pe=[404,408,425,429,500,502,503,504];function Ee(t){return Pe.includes(t)}var b=class extends Error{constructor(e){super(e),this.name="IllegalArgumentError",Object.setPrototypeOf(this,b.prototype)}},h=class extends Error{constructor(r,n,i,s,o,l){super();this.statusCode=r;this.statusMessage=n;this.body=i;this.contentType=o;if(Object.setPrototypeOf(this,h.prototype),l)this.message=l;else if(i){if(o!=null&&o.startsWith("application/json"))try{this.json=JSON.parse(i),this.message=this.json.message,this.code=this.json.code}catch(f){}this.message||(this.message=`${r} ${n} : ${i}`)}else this.message=`${r} ${n}`;this.name="HttpError",this.setRetryAfter(s)}setRetryAfter(r){typeof r=="string"?/^[0-9]+$/.test(r)?this._retryAfter=parseInt(r):this._retryAfter=0:this._retryAfter=0}canRetry(){return Ee(this.statusCode)}retryAfter(){return this._retryAfter}},Fe=["ECONNRESET","ENOTFOUND","ESOCKETTIMEDOUT","ETIMEDOUT","ECONNREFUSED","EHOSTUNREACH","EPIPE"];function Je(t){if(t){if(typeof t.canRetry=="function")return!!t.canRetry();if(t.code&&Fe.includes(t.code))return!0}else return!1;return!1}function oe(t,e){if(t){let r;return typeof t.retryAfter=="function"?t.retryAfter():(r=0,e&&e>0?r+Math.round(Math.random()*e):r)}else return 0}var U=class extends Error{constructor(){super(),Object.setPrototypeOf(this,U.prototype),this.name="RequestTimedOutError",this.message="Request timed out"}canRetry(){return!0}retryAfter(){return 0}},B=class extends Error{constructor(){super(),this.name="AbortError",Object.setPrototypeOf(this,B.prototype),this.message="Response aborted"}canRetry(){return!0}retryAfter(){return 0}};function Ze(){C["dateTime:RFC3339"]=t=>t===""?null:new Date(Date.parse(t))}function et(){C["dateTime:RFC3339"]=t=>t===""?null:Date.parse(t)}function tt(){C["dateTime:RFC3339"]=t=>t===""?null:t}var W=class{constructor(e){e.forEach((r,n)=>r.index=n),this.columns=e}column(e,r=!0){for(let n=0;n<this.columns.length;n++){let i=this.columns[n];if(i.label===e)return i}if(r)throw new b(`Column ${e} not found!`);return ie}toObject(e){let r={};for(let n=0;n<this.columns.length&&n<e.length;n++){let i=this.columns[n];r[i.label]=i.get(e)}return r}get(e,r){return this.column(r,!1).get(e)}};function ae(t){return new W(t)}function N(t){let e=new $().withReuse(),r,n=!0,i=0,s,o={error(l){t.error(l)},next(l){if(l==="")n=!0,r=void 0;else{let f=e.splitLine(l),c=e.lastSplitLength;if(n){if(!r){r=new Array(c);for(let a=0;a<c;a++)r[a]=se()}if(f[0].startsWith("#")){if(f[0]==="#datatype")for(let a=1;a<c;a++)r[a].dataType=f[a];else if(f[0]==="#default")for(let a=1;a<c;a++)r[a].defaultValue=f[a];else if(f[0]==="#group")for(let a=1;a<c;a++)r[a].group=f[a][0]==="t"}else{f[0]===""?(i=1,r=r.slice(1)):i=0;for(let a=i;a<c;a++)r[a-i].label=f[a];s=ae(r),n=!1}}else return t.next(f.slice(i,c),s)}return!0},complete(){t.complete()}};return t.useCancellable&&(o.useCancellable=t.useCancellable.bind(t)),t.useResume&&(o.useResume=t.useResume.bind(t)),o}function ft(t,e){let r=!1,n=0,i=0;for(;i<t.length;){let s=t.charCodeAt(i);if(s===10){if(!r){let o=i>0&&t.charCodeAt(i-1)===13?i-1:i;e.next(t.substring(n,o)),n=i+1}}else s===34&&(r=!r);i++}n<i&&e.next(t.substring(n,i)),e.complete()}var le=(()=>typeof Symbol=="function"&&Symbol.observable||"@@observable")();var j=class{constructor(e,r){this.isClosed=!1;try{r({next:n=>{e.next(n)},error:n=>{this.isClosed=!0,e.error(n)},complete:()=>{this.isClosed=!0,e.complete()},useCancellable:n=>{this.cancellable=n}})}catch(n){this.isClosed=!0,e.error(n)}}get closed(){return this.isClosed}unsubscribe(){var e;(e=this.cancellable)==null||e.cancel(),this.isClosed=!0}};function k(){}function Le(t){let{next:e,error:r,complete:n}=t;return{next:e?e.bind(t):k,error:r?r.bind(t):k,complete:n?n.bind(t):k}}var T=class{constructor(e,r){this.executor=e;this.decorator=r}subscribe(e,r,n){let i=Le(typeof e!="object"||e===null?{next:e,error:r,complete:n}:e);return new j(this.decorator(i),this.executor)}[le](){return this}};Symbol.observable;var Mt={timeout:1e4},ue={retryJitter:200,minRetryDelay:5e3,maxRetryDelay:125e3,exponentialBase:5,randomRetry:!0},fe={batchSize:1e3,maxBatchBytes:5e7,flushInterval:6e4,writeFailed:function(){},writeSuccess:function(){},writeRetrySkipped:function(){},maxRetries:5,maxRetryTime:18e4,maxBufferLines:32e3,retryJitter:200,minRetryDelay:5e3,maxRetryDelay:125e3,exponentialBase:2,gzipThreshold:1e3,randomRetry:!0};function Q(t,e){return function(r){let n="",i=0,s=0;for(;s<r.length;){let o=t.indexOf(r[s]);o>=0&&(n+=r.substring(i,s),n+=e[o],i=s+1),s++}return i==0?r:(i<r.length&&(n+=r.substring(i,r.length)),n)}}function $e(t,e){let r=Q(t,e);return n=>'"'+r(n)+'"'}var w={measurement:Q(`,
|
|
2
|
+
\r `,["\\,","\\ ","\\n","\\r","\\t"]),quoted:$e('"\\',['\\"',"\\\\"]),tag:Q(`, =
|
|
3
|
+
\r `,["\\,","\\ ","\\=","\\n","\\r","\\t"])};var he="000000000";function Ie(t){return!1}Ie(!0);var ce=Date.now(),q=0;function J(){{let t=Date.now();t!==ce?(ce=t,q=0):q++;let e=String(q);return String(t)+he.substr(0,6-e.length)+e}}function me(){return String(Date.now())+he.substr(0,3)}function de(){return String(Date.now())}function pe(){return String(Math.floor(Date.now()/1e3))}var ge={s:pe,ms:de,us:me,ns:J,seconds:pe,millis:de,micros:me,nanos:J},ye={s:t=>`${Math.floor(t.getTime()/1e3)}`,ms:t=>`${t.getTime()}`,us:t=>`${t.getTime()}000`,ns:t=>`${t.getTime()}000000`};function be(t){return t===void 0?J():typeof t=="string"?t.length>0?t:void 0:t instanceof Date?`${t.getTime()}000000`:String(typeof t=="number"?Math.floor(t):t)}var Ue={error(t,e){console.error("ERROR: "+t,e||"")},warn(t,e){console.warn("WARN: "+t,e||"")}},_=Ue,g={error(t,e){_.error(t,e)},warn(t,e){_.warn(t,e)}};function Wt(t){let e=_;return _=t,e}var M=Symbol("FLUX_VALUE"),y=class{constructor(e){this.fluxValue=e}toString(){return this.fluxValue}[M](){return this.fluxValue}};function Be(t){return typeof t=="object"&&typeof t[M]=="function"}function O(t){if(t==null)return"";t=t.toString();let e,r=0;function n(){e===void 0&&(e=t.substring(0,r))}for(;r<t.length;r++){let i=t.charAt(r);switch(i){case"\r":n(),e+="\\r";break;case`
|
|
4
|
+
`:n(),e+="\\n";break;case" ":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}e!=null&&(e+=i);break;default:e!=null&&(e+=i)}}return e!==void 0?e:t}function kt(t){return new y(`"${O(t)}"`)}function Te(t){let e=Number(t);if(!isFinite(e)){if(typeof t=="number")return`float(v: "${e}")`;throw new Error(`not a flux float: ${t}`)}let r=e.toString(),n=!1;for(let i of r)if(!(i>="0"&&i<="9"||i=="-")){if(i==="."){n=!0;continue}return`float(v: "${r}")`}return n?r:r+".0"}function jt(t){return new y(Te(t))}function we(t){let e=String(t),r=e.startsWith("-"),n=r?e.substring(1):e;if(n.length===0||n.length>19)throw new Error(`not a flux integer: ${e}`);for(let i of n)if(i<"0"||i>"9")throw new Error(`not a flux integer: ${e}`);if(n.length===19){if(r&&n>"9223372036854775808")throw new Error(`flux integer out of bounds: ${e}`);if(!r&&n>"9223372036854775807")throw new Error(`flux integer out of bounds: ${e}`)}return e}function Qt(t){return new y(we(t))}function _e(t){return`time(v: "${O(t)}")`}function qt(t){return new y(_e(t))}function Jt(t){return new y(`duration(v: "${O(t)}")`)}function Re(t){return t instanceof RegExp?t.toString():new RegExp(t).toString()}function Xt(t){return new y(Re(t))}function Gt(t){return t==="true"||t==="false"?new y(t):new y((!!t).toString())}function xe(t){return new y(String(t))}function X(t){if(t===void 0)return"";if(t===null)return"null";if(typeof t=="boolean")return t.toString();if(typeof t=="string")return`"${O(t)}"`;if(typeof t=="number")return Number.isSafeInteger(t)?we(t):Te(t);if(typeof t=="object"){if(typeof t[M]=="function")return t[M]();if(t instanceof Date)return t.toISOString();if(t instanceof RegExp)return Re(t);if(Array.isArray(t))return`[${t.map(X).join(",")}]`}else if(typeof t=="bigint")return`${t}.0`;return X(t.toString())}function Kt(t,...e){if(t.length==1&&e.length===0)return xe(t[0]);let r=new Array(t.length+e.length),n=0;for(let i=0;i<t.length;i++){let s=t[i];if(r[n++]=s,i<e.length){let o=e[i],l;if(s.endsWith('"')&&i+1<t.length&&t[i+1].startsWith('"'))l=O(o);else if(l=X(o),l===""&&!Be(o))throw new Error(`Unsupported parameter literal '${o}' at index: ${i}, type: ${typeof o}`);r[n++]=l}else if(i<t.length-1)throw new Error("Too few parameters supplied!")}return xe(r.join(""))}var Ce=class{constructor(e){this.tags={};this.fields={};e&&(this.name=e)}measurement(e){return this.name=e,this}tag(e,r){return this.tags[e]=r,this}booleanField(e,r){return this.fields[e]=r?"T":"F",this}intField(e,r){let n;if(typeof r=="number"?n=r:n=parseInt(String(r)),isNaN(n)||n<=-9223372036854776e3||n>=9223372036854776e3)throw new Error(`invalid integer value for field '${e}': '${r}'!`);return this.fields[e]=`${Math.floor(n)}i`,this}uintField(e,r){if(typeof r=="number"){if(isNaN(r)||r<0||r>Number.MAX_SAFE_INTEGER)throw new Error(`uint value for field '${e}' out of range: ${r}`);this.fields[e]=`${Math.floor(r)}u`}else{let n=String(r);for(let i=0;i<n.length;i++){let s=n.charCodeAt(i);if(s<48||s>57)throw new Error(`uint value has an unsupported character at pos ${i}: ${r}`)}if(n.length>20||n.length===20&&n.localeCompare("18446744073709551615")>0)throw new Error(`uint value for field '${e}' out of range: ${n}`);this.fields[e]=`${n}u`}return this}floatField(e,r){let n;if(typeof r=="number"?n=r:n=parseFloat(r),!isFinite(n))throw new Error(`invalid float value for field '${e}': ${r}`);return this.fields[e]=String(n),this}stringField(e,r){return r!=null&&(typeof r!="string"&&(r=String(r)),this.fields[e]=w.quoted(r)),this}timestamp(e){return this.time=e,this}toLineProtocol(e){if(!this.name)return;let r="";if(Object.keys(this.fields).sort().forEach(o=>{if(o){let l=this.fields[o];r.length>0&&(r+=","),r+=`${w.tag(o)}=${l}`}}),r.length===0)return;let n="",i=e&&e.defaultTags?d(d({},e.defaultTags),this.tags):this.tags;Object.keys(i).sort().forEach(o=>{if(o){let l=i[o];l&&(n+=",",n+=`${w.tag(o)}=${w.tag(l)}`)}});let s=this.time;return e&&e.convertTime?s=e.convertTime(s):s=be(s),`${w.measurement(this.name)}${n} ${r}${s!==void 0?" "+s:""}`}toString(){let e=this.toLineProtocol(void 0);return e||`invalid point: ${JSON.stringify(this,void 0)}`}};var G=class{constructor(e){this.options=d(d({},ue),e),this.success()}nextDelay(e,r){let n=oe(e);if(n&&n>0)return n+Math.round(Math.random()*this.options.retryJitter);if(r&&r>0){if(this.options.randomRetry){let s=Math.max(this.options.minRetryDelay,1),o=s*this.options.exponentialBase;for(let l=1;l<r;l++)if(s=o,o=o*this.options.exponentialBase,o>=this.options.maxRetryDelay){o=this.options.maxRetryDelay;break}return s+Math.round(Math.random()*(o-s)+Math.random()*this.options.retryJitter)}let i=Math.max(this.options.minRetryDelay,1);for(let s=1;s<r;s++)if(i=i*this.options.exponentialBase,i>=this.options.maxRetryDelay){i=this.options.maxRetryDelay;break}return i+Math.round(Math.random()*this.options.retryJitter)}else 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);return this.currentDelay}success(){this.currentDelay=void 0}};function Oe(t){return new G(t)}function Me(t){let e,r=t,n=t;for(;n.next;)n.next.expires<r.expires&&(e=n,r=n.next),n=n.next;return[r,e]}var S=class{constructor(e,r,n=()=>{}){this.maxLines=e;this.retryLines=r;this.onShrink=n;this.size=0;this.closed=!1;this._timeoutHandle=void 0}addLines(e,r,n,i){if(this.closed||!e.length)return;let s=Date.now()+n;if(i<s&&(s=i),this.first&&this.size+e.length>this.maxLines){let c=this.size,a=c*.7;do{let[u,m]=Me(this.first);this.size-=u.lines.length,m?m.next=u.next:(this.first=u.next,this.first&&this.scheduleRetry(this.first.retryTime-Date.now())),u.next=void 0,this.onShrink(u)}while(this.first&&this.size+e.length>a);g.error(`RetryBuffer: ${c-this.size} oldest lines removed to keep buffer size under the limit of ${this.maxLines} lines.`)}let o={lines:e,retryCount:r,retryTime:s,expires:i},l=this.first,f;for(;;){if(!l||l.retryTime>s){o.next=l,f?f.next=o:(this.first=o,this.scheduleRetry(s-Date.now()));break}f=l,l=l.next}this.size+=e.length}removeLines(){if(this.first){let e=this.first;return this.first=this.first.next,e.next=void 0,this.size-=e.lines.length,e}}scheduleRetry(e){this._timeoutHandle&&clearTimeout(this._timeoutHandle),this._timeoutHandle=setTimeout(()=>{let r=this.removeLines();r?this.retryLines(r.lines,r.retryCount,r.expires).finally(()=>{this.first&&this.scheduleRetry(this.first.retryTime-Date.now())}):this._timeoutHandle=void 0},Math.max(e,0))}flush(){return x(this,null,function*(){let e;for(;e=this.removeLines();)yield this.retryLines(e.lines,e.retryCount,e.expires)})}close(){return this._timeoutHandle&&(clearTimeout(this._timeoutHandle),this._timeoutHandle=void 0),this.closed=!0,this.size}};function K(t){let e=t.length;for(let r=0;r<t.length;r++){let n=t.charCodeAt(r);n<128||(n>=128&&n<=2047?e++:n>=2048&&n<=65535?n>=55296&&n<=57343?e++:e+=2:e+=3)}return e}var Y=class{constructor(e,r,n,i){this.maxChunkRecords=e;this.maxBatchBytes=r;this.flushFn=n;this.scheduleSend=i;this.length=0;this.bytes=-1;this.lines=new Array(e)}add(e){let r=K(e);this.length===0?this.scheduleSend():this.bytes+r+1>=this.maxBatchBytes&&this.flush().catch(n=>{}),this.lines[this.length]=e,this.length++,this.bytes+=r+1,(this.length>=this.maxChunkRecords||this.bytes>=this.maxBatchBytes)&&this.flush().catch(n=>{})}flush(){let e=this.reset();return e.length>0?this.flushFn(e):Promise.resolve()}reset(){let e=this.lines.slice(0,this.length);return this.length=0,this.bytes=-1,e}},v=class{constructor(e,r,n,i,s){this.transport=e;this.closed=!1;this._timeoutHandle=void 0;this.path=`/api/v2/write?org=${encodeURIComponent(r)}&bucket=${encodeURIComponent(n)}&precision=${i}`,s!=null&&s.consistency&&(this.path+=`&consistency=${encodeURIComponent(s.consistency)}`),this.writeOptions=d(d({},fe),s),this.currentTime=ge[i],this.dateToProtocolTimestamp=ye[i],this.writeOptions.defaultTags&&this.useDefaultTags(this.writeOptions.defaultTags),this.sendOptions={method:"POST",headers:d({"content-type":"text/plain; charset=utf-8"},s==null?void 0:s.headers),gzipThreshold:this.writeOptions.gzipThreshold};let o=()=>{this.writeOptions.flushInterval>0&&(this._clearFlushTimeout(),this.closed||(this._timeoutHandle=setTimeout(()=>this.sendBatch(this.writeBuffer.reset(),this.writeOptions.maxRetries).catch(l=>{}),this.writeOptions.flushInterval)))};this.writeBuffer=new Y(this.writeOptions.batchSize,this.writeOptions.maxBatchBytes,l=>(this._clearFlushTimeout(),this.sendBatch(l,this.writeOptions.maxRetries)),o),this.sendBatch=this.sendBatch.bind(this),this.retryStrategy=Oe(this.writeOptions),this.retryBuffer=new S(this.writeOptions.maxBufferLines,this.sendBatch,this.writeOptions.writeRetrySkipped)}sendBatch(e,r,n=Date.now()+this.writeOptions.maxRetryTime){let i=this,s=i.writeOptions.maxRetries+1-r;if(!this.closed&&e.length>0){if(n<=Date.now()){let o=new Error("Max retry time exceeded."),l=i.writeOptions.writeFailed.call(i,o,e,s,n);return l||(g.error(`Write to InfluxDB failed (attempt: ${s}).`,o),Promise.reject(o))}return new Promise((o,l)=>{let f,c={responseStarted(a,u){f=u},error(a){let u=i.writeOptions.writeFailed.call(i,a,e,s,n);if(u){u.then(o,l);return}if(a instanceof h&&a.json&&typeof a.json.error=="string"&&a.json.error.includes("hinted handoff queue not empty")){g.warn("Write to InfluxDB returns: "+a.json.error),f=204,c.complete();return}if(!i.closed&&r>0&&(!(a instanceof h)||a.statusCode>=429)){g.warn(`Write to InfluxDB failed (attempt: ${s}).`,a),i.retryBuffer.addLines(e,r-1,i.retryStrategy.nextDelay(a,s),n),l(a);return}g.error("Write to InfluxDB failed.",a),l(a)},complete(){if(f==204||f==null)i.writeOptions.writeSuccess.call(i,e),i.retryStrategy.success(),o();else{let a=`204 HTTP response status code expected, but ${f} returned`,u=new h(f,a,void 0,"0");u.message=a,c.error(u)}}};this.transport.send(this.path,e.join(`
|
|
5
|
+
`),this.sendOptions,c)})}else return Promise.resolve()}_clearFlushTimeout(){this._timeoutHandle!==void 0&&(clearTimeout(this._timeoutHandle),this._timeoutHandle=void 0)}writeRecord(e){if(this.closed)throw new Error("writeApi: already closed!");this.writeBuffer.add(e)}writeRecords(e){if(this.closed)throw new Error("writeApi: already closed!");for(let r=0;r<e.length;r++)this.writeBuffer.add(e[r])}writePoint(e){if(this.closed)throw new Error("writeApi: already closed!");let r=e.toLineProtocol(this);r&&this.writeBuffer.add(r)}writePoints(e){if(this.closed)throw new Error("writeApi: already closed!");for(let r=0;r<e.length;r++){let n=e[r].toLineProtocol(this);n&&this.writeBuffer.add(n)}}flush(e){return x(this,null,function*(){if(yield this.writeBuffer.flush(),e)return yield this.retryBuffer.flush()})}close(){return this.writeBuffer.flush().finally(()=>{let r=this.retryBuffer.close();r&&g.error(`Retry buffer closed with ${r} 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(e){return this.defaultTags=e,this}convertTime(e){return e===void 0?this.currentTime():typeof e=="string"?e.length>0?e:void 0:e instanceof Date?this.dateToProtocolTimestamp(e):String(typeof e=="number"?Math.floor(e):e)}};function Z(t={}){let e=0,r={next:n=>{if(e===0&&t.next&&n!==null&&n!==void 0)return t.next(n)},error:n=>{e===0&&(e=1,t.error&&t.error(n))},complete:()=>{e===0&&(e=2,t.complete&&t.complete())},responseStarted:(n,i)=>{t.responseStarted&&t.responseStarted(n,i)}};return t.useCancellable&&(r.useCancellable=t.useCancellable.bind(t)),t.useResume&&(r.useResume=t.useResume.bind(t)),r}function Se(t){let e={};return t.headers.forEach((r,n)=>{let i=e[n];i===void 0?e[n]=r:Array.isArray(i)?i.push(r):e[n]=[i,r]}),e}var D=class{constructor(e){this.connectionOptions=e;this.chunkCombiner=L();this.requestDecorator=function(){};this.defaultHeaders=d({"content-type":"application/json; charset=utf-8"},e.headers),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-7),g.warn(`Please remove '/api/v2' context path from InfluxDB base url, using ${this.url} !`))}send(e,r,n,i){let s=Z(i),o=!1,l=n.signal,f,c=()=>{},a=c;if(i&&i.useCancellable){let u=new AbortController;l||(l=u.signal,n=d(d({},n),l)),l.addEventListener("abort",()=>{a()}),i.useCancellable({cancel(){o=!0,u.abort()},isCancelled(){return o||l.aborted}})}this.fetch(e,r,n).then(u=>x(this,null,function*(){if(i!=null&&i.responseStarted&&s.responseStarted(Se(u),u.status),u.status>=300)return u.text().then(m=>{if(!m){let p=u.headers.get("x-influxdb-error");p&&(m=p)}s.error(new h(u.status,u.statusText,m,u.headers.get("retry-after"),u.headers.get("content-type")))}).catch(m=>{g.warn("Unable to receive error body",m),s.error(new h(u.status,u.statusText,void 0,u.headers.get("retry-after"),u.headers.get("content-type")))});if(u.body){let m=u.body.getReader(),p;do{if(f&&(yield f),o)break;if(p=yield m.read(),s.next(p.value)===!1){let P=s.useResume;if(!P){let E="Unable to pause, useResume is not configured!";return yield m.cancel(E),Promise.reject(new Error(E))}f=new Promise(E=>{a=()=>{E(),f=void 0,a=c},P(a)})}}while(!p.done)}else if(u.arrayBuffer){let m=yield u.arrayBuffer();s.next(new Uint8Array(m))}else{let m=yield u.text();s.next(new TextEncoder().encode(m))}})).catch(u=>{o||s.error(u)}).finally(()=>s.complete())}request(e,r,n,i){return x(this,null,function*(){var a,u;let s=yield this.fetch(e,r,n),{status:o,headers:l}=s,f=l.get("content-type")||"";if(i&&i(Se(s),s.status),o>=300){let m=yield s.text();if(!m){let p=l.get("x-influxdb-error");p&&(m=p)}throw new h(o,s.statusText,m,s.headers.get("retry-after"),s.headers.get("content-type"))}let c=(u=(a=n.headers)==null?void 0:a.accept)!=null?u:f;if(c.includes("json"))return yield s.json();if(c.includes("text")||c.startsWith("application/csv"))return yield s.text()})}fetch(e,r,n){let c=n,{method:i,headers:s}=c,o=ne(c,["method","headers"]),l=`${this.url}${e}`,f=d(d({method:i,body:i==="GET"||i==="HEAD"?void 0:typeof r=="string"?r:JSON.stringify(r),headers:d(d({},this.defaultHeaders),s),credentials:"omit"},this.connectionOptions.transportOptions),o);return this.requestDecorator(f,n,l),fetch(l,f)}};var ve={header:!0,delimiter:",",quoteChar:'"',commentPrefix:"#",annotations:["datatype","group","default"]},A=class{constructor(e,r,n){this.transport=e;this.createCSVResponse=r;this.options=typeof n=="string"?{org:n}:n}with(e){return new A(this.transport,this.createCSVResponse,d(d({},this.options),e))}response(e){return this.createCSVResponse(this.createExecutor(e))}lines(e){return this.response(e).lines()}rows(e){return this.response(e).rows()}queryLines(e,r){return this.response(e).consumeLines(r)}queryRows(e,r){return this.response(e).consumeRows(r)}collectRows(e,r){return this.response(e).collectRows(r)}collectLines(e){return this.response(e).collectLines()}queryRaw(e){let{org:r,type:n,gzip:i,headers:s}=this.options;return this.transport.request(`/api/v2/query?org=${encodeURIComponent(r)}`,JSON.stringify(this.decorateRequest({query:e.toString(),dialect:ve,type:n})),{method:"POST",headers:d({accept:"text/csv","accept-encoding":i?"gzip":"identity","content-type":"application/json; encoding=utf-8"},s)})}createExecutor(e){let{org:r,type:n,gzip:i,headers:s}=this.options;return o=>{this.transport.send(`/api/v2/query?org=${encodeURIComponent(r)}`,JSON.stringify(this.decorateRequest({query:e.toString(),dialect:ve,type:n})),{method:"POST",headers:d({"content-type":"application/json; encoding=utf-8","accept-encoding":i?"gzip":"identity"},s)},o)}}decorateRequest(e){var r;return typeof this.options.now=="function"&&(e.now=this.options.now()),e.type=(r=this.options.type)!=null?r:"flux",e}},De=A;function Ve(t,e){return e.toObject(t)}var V=class{constructor(e,r){this.executor=e;this.chunkCombiner=r}lines(){return new T(this.executor,e=>R(e,this.chunkCombiner))}rows(){return new T(this.executor,e=>R(N({next(r,n){e.next({values:r,tableMeta:n})},error(r){e.error(r)},complete(){e.complete()}}),this.chunkCombiner))}consumeLines(e){this.executor(R(e,this.chunkCombiner))}consumeRows(e){this.executor(R(N(e),this.chunkCombiner))}collectRows(e=Ve){let r=[];return new Promise((n,i)=>{this.consumeRows({next(s,o){let l=e.call(this,s,o);l!==void 0&&r.push(l)},error(s){i(s)},complete(){n(r)}})})}collectLines(){let e=[];return new Promise((r,n)=>{this.consumeLines({next(i){e.push(i)},error(i){n(i)},complete(){r(e)}})})}};var z=class{constructor(e){var n;if(typeof e=="string")this._options={url:e};else if(e!==null&&typeof e=="object")this._options=e;else throw new b("No url or configuration specified!");let r=this._options.url;if(typeof r!="string")throw new b("No url specified!");r.endsWith("/")&&(this._options.url=r.substring(0,r.length-1)),this.transport=(n=this._options.transport)!=null?n:new D(this._options),this.processCSVResponse=i=>new V(i,this.transport.chunkCombiner)}getWriteApi(e,r,n="ns",i){return new v(this.transport,e,r,n,i!=null?i:this._options.writeOptions)}getQueryApi(e){return new De(this.transport,this.processCSVResponse,e)}};export{B as AbortError,Mt as DEFAULT_ConnectionOptions,ue as DEFAULT_RetryDelayStrategyOptions,fe as DEFAULT_WriteOptions,M as FLUX_VALUE,h as HttpError,b as IllegalArgumentError,z as InfluxDB,$ as LineSplitter,g as Log,Ce as Point,U as RequestTimedOutError,ie as UNKNOWN_COLUMN,Je as canRetryHttpCall,R as chunksToLines,Ue as consoleLogger,be as convertTimeToNanos,Qe as createFluxTableColumn,ae as createFluxTableMetaData,L as createTextDecoderCombiner,ge as currentTime,ye as dateToProtocolTimestamp,w as escape,Kt as flux,Gt as fluxBool,qt as fluxDateTime,Jt as fluxDuration,xe as fluxExpression,jt as fluxFloat,Qt as fluxInteger,Xt as fluxRegExp,kt as fluxString,oe as getRetryDelay,Ee as isStatusCodeRetriable,N as linesToTables,se as newFluxTableColumn,Te as sanitizeFloat,we as sanitizeInteger,Ze as serializeDateTimeAsDate,et as serializeDateTimeAsNumber,tt as serializeDateTimeAsString,Wt as setLogger,ft as stringToLines,le as symbolObservable,X as toFluxValue,C as typeSerializers,Ie as useProcessHrtime};
|
|
6
6
|
//# sourceMappingURL=index.browser.mjs.map
|
|
Binary file
|