@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.d.ts
CHANGED
|
@@ -65,8 +65,10 @@ interface CommunicationObserver<T> {
|
|
|
65
65
|
/**
|
|
66
66
|
* Data chunk received, can be called multiple times.
|
|
67
67
|
* @param data - data
|
|
68
|
+
* @returns when `false` value is returned and {@link CommunicationObserver.useResume} is defined,
|
|
69
|
+
* future calls to `next` are paused until resume is called.
|
|
68
70
|
*/
|
|
69
|
-
next(data: T): void;
|
|
71
|
+
next(data: T): void | boolean;
|
|
70
72
|
/**
|
|
71
73
|
* Communication ended with an error.
|
|
72
74
|
*/
|
|
@@ -83,6 +85,13 @@ interface CommunicationObserver<T> {
|
|
|
83
85
|
* Setups cancelllable for this communication.
|
|
84
86
|
*/
|
|
85
87
|
useCancellable?: (cancellable: Cancellable) => void;
|
|
88
|
+
/**
|
|
89
|
+
* Setups a callback that resumes reading of next data, it is called whenever
|
|
90
|
+
* {@link CommunicationObserver.next} returns `false`.
|
|
91
|
+
*
|
|
92
|
+
* @param resume - a function that will resume reading of next data when called
|
|
93
|
+
*/
|
|
94
|
+
useResume?: (resume: () => void) => void;
|
|
86
95
|
}
|
|
87
96
|
|
|
88
97
|
/**
|
|
@@ -217,8 +226,12 @@ interface Row {
|
|
|
217
226
|
interface FluxResultObserver<T> {
|
|
218
227
|
/**
|
|
219
228
|
* Inform about a next record in a table.
|
|
229
|
+
* @param row - flux result
|
|
230
|
+
* @param tableMeta - actual table metata for the row supplied
|
|
231
|
+
* @returns when `false` value is returned and {@link FluxResultObserver.useResume} is defined,
|
|
232
|
+
* future calls to `next` are paused until resume is called.
|
|
220
233
|
*/
|
|
221
|
-
next(row: T, tableMeta: FluxTableMetaData): void;
|
|
234
|
+
next(row: T, tableMeta: FluxTableMetaData): void | boolean;
|
|
222
235
|
/**
|
|
223
236
|
* Signalizes processing error.
|
|
224
237
|
*/
|
|
@@ -231,6 +244,13 @@ interface FluxResultObserver<T> {
|
|
|
231
244
|
* Setups cancellable that can abort flux result processing.
|
|
232
245
|
*/
|
|
233
246
|
useCancellable?: (cancellable: Cancellable) => void;
|
|
247
|
+
/**
|
|
248
|
+
* Setups a callback that resumes reading of next data, it is called whenever
|
|
249
|
+
* {@link FluxResultObserver.next} returns `false`.
|
|
250
|
+
*
|
|
251
|
+
* @param resume - a function that will resume reading of next data when called
|
|
252
|
+
*/
|
|
253
|
+
useResume?: (resume: () => void) => void;
|
|
234
254
|
}
|
|
235
255
|
|
|
236
256
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var Xe=Object.create;var O=Object.defineProperty,Ye=Object.defineProperties,Ge=Object.getOwnPropertyDescriptor,Ke=Object.getOwnPropertyDescriptors,Ze=Object.getOwnPropertyNames,
|
|
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(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 ht(t){return new g(`"${D(t)}"`)}function de(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 gt(t){return new g(de(t))}function he(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 yt(t){return new g(he(t))}function bt(t){return`time(v: "${D(t)}")`}function xt(t){return new g(bt(t))}function Tt(t){return new g(`duration(v: "${D(t)}")`)}function ke(t){return t instanceof RegExp?t.toString():new RegExp(t).toString()}function wt(t){return new g(ke(t))}function Ct(t){return t==="true"||t==="false"?new g(t):new g((!!t).toString())}function me(t){return new g(String(t))}function M(t){if(t===void 0)return"";if(t===null)return"null";if(typeof t=="boolean")return t.toString();if(typeof t=="string")return`"${D(t)}"`;if(typeof t=="number")return Number.isSafeInteger(t)?he(t):de(t);if(typeof t=="object"){if(typeof t[A]=="function")return t[A]();if(t instanceof Date)return t.toISOString();if(t instanceof RegExp)return ke(t);if(Array.isArray(t))return`[${t.map(M).join(",")}]`}else if(typeof t=="bigint")return`${t}.0`;return M(t.toString())}function Rt(t,...e){if(t.length==1&&e.length===0)return me(t[0]);let r=new Array(t.length+e.length),n=0;for(let i=0;i<t.length;i++){let o=t[i];if(r[n++]=o,i<e.length){let s=e[i],a;if(o.endsWith('"')&&i+1<t.length&&t[i+1].startsWith('"'))a=D(s);else if(a=M(s),a===""&&!dt(s))throw new Error(`Unsupported parameter literal '${s}' at index: ${i}, type: ${typeof s}`);r[n++]=a}else if(i<t.length-1)throw new Error("Too few parameters supplied!")}return me(r.join(""))}var ge=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 o=n.charCodeAt(i);if(o<48||o>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]=T.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(s=>{if(s){let a=this.fields[s];r.length>0&&(r+=","),r+=`${T.tag(s)}=${a}`}}),r.length===0)return;let n="",i=e&&e.defaultTags?p(p({},e.defaultTags),this.tags):this.tags;Object.keys(i).sort().forEach(s=>{if(s){let a=i[s];a&&(n+=",",n+=`${T.tag(s)}=${T.tag(a)}`)}});let o=this.time;return e&&e.convertTime?o=e.convertTime(o):o=pe(o),`${T.measurement(this.name)}${n} ${r}${o!==void 0?" "+o:""}`}toString(){let e=this.toLineProtocol(void 0);return e||`invalid point: ${JSON.stringify(this,void 0)}`}};var ye=class{constructor(e){this.options=p(p({},ie),e),this.success()}nextDelay(e,r){let n=G(e);if(n&&n>0)return n+Math.round(Math.random()*this.options.retryJitter);if(r&&r>0){if(this.options.randomRetry){let o=Math.max(this.options.minRetryDelay,1),s=o*this.options.exponentialBase;for(let a=1;a<r;a++)if(o=s,s=s*this.options.exponentialBase,s>=this.options.maxRetryDelay){s=this.options.maxRetryDelay;break}return o+Math.round(Math.random()*(s-o)+Math.random()*this.options.retryJitter)}let i=Math.max(this.options.minRetryDelay,1);for(let o=1;o<r;o++)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 Me(t){return new ye(t)}function St(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 P=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 o=Date.now()+n;if(i<o&&(o=i),this.first&&this.size+e.length>this.maxLines){let u=this.size,f=u*.7;do{let[c,m]=St(this.first);this.size-=c.lines.length,m?m.next=c.next:(this.first=c.next,this.first&&this.scheduleRetry(this.first.retryTime-Date.now())),c.next=void 0,this.onShrink(c)}while(this.first&&this.size+e.length>f);h.error(`RetryBuffer: ${u-this.size} oldest lines removed to keep buffer size under the limit of ${this.maxLines} lines.`)}let s={lines:e,retryCount:r,retryTime:o,expires:i},a=this.first,l;for(;;){if(!a||a.retryTime>o){s.next=a,l?l.next=s:(this.first=s,this.scheduleRetry(o-Date.now()));break}l=a,a=a.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 I(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 be(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 xe=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=be(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}},E=class{constructor(e,r,n,i,o){this.transport=e;this.closed=!1;this._timeoutHandle=void 0;this.path=`/api/v2/write?org=${encodeURIComponent(r)}&bucket=${encodeURIComponent(n)}&precision=${i}`,o!=null&&o.consistency&&(this.path+=`&consistency=${encodeURIComponent(o.consistency)}`),this.writeOptions=p(p({},oe),o),this.currentTime=fe[i],this.dateToProtocolTimestamp=ce[i],this.writeOptions.defaultTags&&this.useDefaultTags(this.writeOptions.defaultTags),this.sendOptions={method:"POST",headers:p({"content-type":"text/plain; charset=utf-8"},o==null?void 0:o.headers),gzipThreshold:this.writeOptions.gzipThreshold};let s=()=>{this.writeOptions.flushInterval>0&&(this._clearFlushTimeout(),this.closed||(this._timeoutHandle=setTimeout(()=>this.sendBatch(this.writeBuffer.reset(),this.writeOptions.maxRetries).catch(a=>{}),this.writeOptions.flushInterval)))};this.writeBuffer=new xe(this.writeOptions.batchSize,this.writeOptions.maxBatchBytes,a=>(this._clearFlushTimeout(),this.sendBatch(a,this.writeOptions.maxRetries)),s),this.sendBatch=this.sendBatch.bind(this),this.retryStrategy=Me(this.writeOptions),this.retryBuffer=new P(this.writeOptions.maxBufferLines,this.sendBatch,this.writeOptions.writeRetrySkipped)}sendBatch(e,r,n=Date.now()+this.writeOptions.maxRetryTime){let i=this,o=i.writeOptions.maxRetries+1-r;if(!this.closed&&e.length>0){if(n<=Date.now()){let s=new Error("Max retry time exceeded."),a=i.writeOptions.writeFailed.call(i,s,e,o,n);return a||(h.error(`Write to InfluxDB failed (attempt: ${o}).`,s),Promise.reject(s))}return new Promise((s,a)=>{let l,u={responseStarted(f,c){l=c},error(f){let c=i.writeOptions.writeFailed.call(i,f,e,o,n);if(c){c.then(s,a);return}if(f instanceof d&&f.json&&typeof f.json.error=="string"&&f.json.error.includes("hinted handoff queue not empty")){h.warn("Write to InfluxDB returns: "+f.json.error),l=204,u.complete();return}if(!i.closed&&r>0&&(!(f instanceof d)||f.statusCode>=429)){h.warn(`Write to InfluxDB failed (attempt: ${o}).`,f),i.retryBuffer.addLines(e,r-1,i.retryStrategy.nextDelay(f,o),n),a(f);return}h.error("Write to InfluxDB failed.",f),a(f)},complete(){if(l==204||l==null)i.writeOptions.writeSuccess.call(i,e),i.retryStrategy.success(),s();else{let f=`204 HTTP response status code expected, but ${l} returned`,c=new d(l,f,void 0,"0");c.message=f,u.error(c)}}};this.transport.send(this.path,e.join(`
|
|
5
|
-
`),this.sendOptions,
|
|
1
|
+
"use strict";var Xe=Object.create;var O=Object.defineProperty,Ye=Object.defineProperties,Ge=Object.getOwnPropertyDescriptor,Ke=Object.getOwnPropertyDescriptors,Ze=Object.getOwnPropertyNames,I=Object.getOwnPropertySymbols,et=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty,Pe=Object.prototype.propertyIsEnumerable;var De=(t,e,r)=>e in t?O(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,c=(t,e)=>{for(var r in e||(e={}))q.call(e,r)&&De(t,r,e[r]);if(I)for(var r of I(e))Pe.call(e,r)&&De(t,r,e[r]);return t},j=(t,e)=>Ye(t,Ke(e));var Ee=(t,e)=>{var r={};for(var n in t)q.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&I)for(var n of I(t))e.indexOf(n)<0&&Pe.call(t,n)&&(r[n]=t[n]);return r};var tt=(t,e)=>{for(var r in e)O(t,r,{get:e[r],enumerable:!0})},Fe=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ze(e))!q.call(t,i)&&i!==r&&O(t,i,{get:()=>e[i],enumerable:!(n=Ge(e,i))||n.enumerable});return t};var Q=(t,e,r)=>(r=t!=null?Xe(et(t)):{},Fe(e||!t||!t.__esModule?O(r,"default",{value:t,enumerable:!0}):r,t)),rt=t=>Fe(O({},"__esModule",{value:!0}),t);var $=(t,e,r)=>new Promise((n,i)=>{var o=l=>{try{u(r.next(l))}catch(p){i(p)}},s=l=>{try{u(r.throw(l))}catch(p){i(p)}},u=l=>l.done?n(l.value):Promise.resolve(l.value).then(o,s);u((r=r.apply(t,e)).next())});var Pt={};tt(Pt,{AbortError:()=>T,DEFAULT_ConnectionOptions:()=>ie,DEFAULT_RetryDelayStrategyOptions:()=>se,DEFAULT_WriteOptions:()=>oe,FLUX_VALUE:()=>A,HttpError:()=>d,IllegalArgumentError:()=>y,InfluxDB:()=>U,LineSplitter:()=>v,Log:()=>h,Point:()=>ye,RequestTimedOutError:()=>x,UNKNOWN_COLUMN:()=>Y,canRetryHttpCall:()=>ot,chunksToLines:()=>C,consoleLogger:()=>Ve,convertTimeToNanos:()=>me,createFluxTableColumn:()=>nt,createFluxTableMetaData:()=>ee,createTextDecoderCombiner:()=>J,currentTime:()=>pe,dateToProtocolTimestamp:()=>ce,escape:()=>R,flux:()=>wt,fluxBool:()=>Ct,fluxDateTime:()=>xt,fluxDuration:()=>Tt,fluxExpression:()=>de,fluxFloat:()=>gt,fluxInteger:()=>yt,fluxRegExp:()=>Rt,fluxString:()=>ht,getRetryDelay:()=>K,isStatusCodeRetriable:()=>Le,linesToTables:()=>z,newFluxTableColumn:()=>G,sanitizeFloat:()=>he,sanitizeInteger:()=>ge,serializeDateTimeAsDate:()=>at,serializeDateTimeAsNumber:()=>ut,serializeDateTimeAsString:()=>lt,setLogger:()=>mt,stringToLines:()=>ft,symbolObservable:()=>te,toFluxValue:()=>N,typeSerializers:()=>w,useProcessHrtime:()=>ze});module.exports=rt(Pt);function J(){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 C(t,e){let r=e!=null?e:J(),n,i=!1,o=!1,s=!1,u;function l(a){let f,m=0;for(n?(f=a.length===0?0:n.length,a=r.concat(n,a)):f=0;f<a.length;){let b=a[f];if(b===10){if(!o){let _=f>0&&a[f-1]===13?f-1:f;if(i)return;if(s=t.next(r.toUtf8String(a,m,_))===!1,m=f+1,s)break}}else b===34&&(o=!o);f++}if(m<a.length?n=r.copy(a,m,a.length):n=void 0,s){if(t.useResume){t.useResume(()=>{s=!1,l(new Uint8Array(0))});return}p.error(new Error("Unable to pause, useResume is not configured!")),s=!1}u&&(u(),u=void 0)}let p={next(a){if(!i)try{return l(a),!s}catch(f){this.error(f)}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&&(p.useCancellable=a=>{t.useCancellable&&t.useCancellable({cancel(){a.cancel(),n=void 0,p.complete()},isCancelled(){return a.isCancelled()}})}),t.useResume&&(p.useResume=a=>{u=a}),p}var v=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:[],o=0;for(let u=0;u<e.length;u++){let l=e[u];if(l===","){if(r%2===0){let p=this.getValue(e,n,u,r);this._reuse?i[o++]=p:i.push(p),n=u+1,r=0}}else l==='"'&&r++}let s=this.getValue(e,n,e.length,r);return this._reuse?(i[o]=s,this.lastSplitLength=o+1):(i.push(s),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 X=t=>t,w={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:X,base64Binary:X,duration:t=>t===""?null:t,"dateTime:RFC3339":t=>t===""?null:t},B=class{get(e){var n;let r=e[this.index];return(r===""||r===void 0)&&this.defaultValue&&(r=this.defaultValue),((n=w[this.dataType])!=null?n:X)(r)}},Y=Object.freeze({label:"",dataType:"",group:!1,defaultValue:"",index:Number.MAX_SAFE_INTEGER,get:()=>{}});function G(){return new B}function nt(t){var r,n;let e=new B;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 it=[404,408,425,429,500,502,503,504];function Le(t){return it.includes(t)}var y=class extends Error{constructor(e){super(e),this.name="IllegalArgumentError",Object.setPrototypeOf(this,y.prototype)}},d=class extends Error{constructor(r,n,i,o,s,u){super();this.statusCode=r;this.statusMessage=n;this.body=i;this.contentType=s;if(Object.setPrototypeOf(this,d.prototype),u)this.message=u;else if(i){if(s!=null&&s.startsWith("application/json"))try{this.json=JSON.parse(i),this.message=this.json.message,this.code=this.json.code}catch(l){}this.message||(this.message=`${r} ${n} : ${i}`)}else this.message=`${r} ${n}`;this.name="HttpError",this.setRetryAfter(o)}setRetryAfter(r){typeof r=="string"?/^[0-9]+$/.test(r)?this._retryAfter=parseInt(r):this._retryAfter=0:this._retryAfter=0}canRetry(){return Le(this.statusCode)}retryAfter(){return this._retryAfter}},st=["ECONNRESET","ENOTFOUND","ESOCKETTIMEDOUT","ETIMEDOUT","ECONNREFUSED","EHOSTUNREACH","EPIPE"];function ot(t){if(t){if(typeof t.canRetry=="function")return!!t.canRetry();if(t.code&&st.includes(t.code))return!0}else return!1;return!1}function K(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 x=class extends Error{constructor(){super(),Object.setPrototypeOf(this,x.prototype),this.name="RequestTimedOutError",this.message="Request timed out"}canRetry(){return!0}retryAfter(){return 0}},T=class extends Error{constructor(){super(),this.name="AbortError",Object.setPrototypeOf(this,T.prototype),this.message="Response aborted"}canRetry(){return!0}retryAfter(){return 0}};function at(){w["dateTime:RFC3339"]=t=>t===""?null:new Date(Date.parse(t))}function ut(){w["dateTime:RFC3339"]=t=>t===""?null:Date.parse(t)}function lt(){w["dateTime:RFC3339"]=t=>t===""?null:t}var Z=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 y(`Column ${e} not found!`);return Y}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 ee(t){return new Z(t)}function z(t){let e=new v().withReuse(),r,n=!0,i=0,o,s={error(u){t.error(u)},next(u){if(u==="")n=!0,r=void 0;else{let l=e.splitLine(u),p=e.lastSplitLength;if(n){if(!r){r=new Array(p);for(let a=0;a<p;a++)r[a]=G()}if(l[0].startsWith("#")){if(l[0]==="#datatype")for(let a=1;a<p;a++)r[a].dataType=l[a];else if(l[0]==="#default")for(let a=1;a<p;a++)r[a].defaultValue=l[a];else if(l[0]==="#group")for(let a=1;a<p;a++)r[a].group=l[a][0]==="t"}else{l[0]===""?(i=1,r=r.slice(1)):i=0;for(let a=i;a<p;a++)r[a-i].label=l[a];o=ee(r),n=!1}}else return t.next(l.slice(i,p),o)}return!0},complete(){t.complete()}};return t.useCancellable&&(s.useCancellable=t.useCancellable.bind(t)),t.useResume&&(s.useResume=t.useResume.bind(t)),s}function ft(t,e){let r=!1,n=0,i=0;for(;i<t.length;){let o=t.charCodeAt(i);if(o===10){if(!r){let s=i>0&&t.charCodeAt(i-1)===13?i-1:i;e.next(t.substring(n,s)),n=i+1}}else o===34&&(r=!r);i++}n<i&&e.next(t.substring(n,i)),e.complete()}var te=(()=>typeof Symbol=="function"&&Symbol.observable||"@@observable")();var ne=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 re(){}function pt(t){let{next:e,error:r,complete:n}=t;return{next:e?e.bind(t):re,error:r?r.bind(t):re,complete:n?n.bind(t):re}}var S=class{constructor(e,r){this.executor=e;this.decorator=r}subscribe(e,r,n){let i=pt(typeof e!="object"||e===null?{next:e,error:r,complete:n}:e);return new ne(this.decorator(i),this.executor)}[te](){return this}};Symbol.observable;var ie={timeout:1e4},se={retryJitter:200,minRetryDelay:5e3,maxRetryDelay:125e3,exponentialBase:5,randomRetry:!0},oe={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 ae(t,e){return function(r){let n="",i=0,o=0;for(;o<r.length;){let s=t.indexOf(r[o]);s>=0&&(n+=r.substring(i,o),n+=e[s],i=o+1),o++}return i==0?r:(i<r.length&&(n+=r.substring(i,r.length)),n)}}function ct(t,e){let r=ae(t,e);return n=>'"'+r(n)+'"'}var R={measurement:ae(`,
|
|
2
|
+
\r `,["\\,","\\ ","\\n","\\r","\\t"]),quoted:ct('"\\',['\\"',"\\\\"]),tag:ae(`, =
|
|
3
|
+
\r `,["\\,","\\ ","\\=","\\n","\\r","\\t"])};var M="000000000",fe=!1;function ze(t){return fe=t&&process&&typeof process.hrtime=="function"}ze(!0);var Ue,V,_e=Date.now(),ue=0;function le(){if(fe){let t=process.hrtime(),e=Date.now();V?(t[0]=t[0]-V[0],t[1]=t[1]-V[1],t[1]<0&&(t[0]-=1,t[1]+=1e9),e=Ue+t[0]*1e3+Math.floor(t[1]/1e6)):(V=t,Ue=e);let r=String(t[1]%1e6);return String(e)+M.substr(0,6-r.length)+r}else{let t=Date.now();t!==_e?(_e=t,ue=0):ue++;let e=String(ue);return String(t)+M.substr(0,6-e.length)+e}}function Ie(){if(fe){let t=process.hrtime(),e=String(Math.trunc(t[1]/1e3)%1e3);return String(Date.now())+M.substr(0,3-e.length)+e}else return String(Date.now())+M.substr(0,3)}function $e(){return String(Date.now())}function Be(){return String(Math.floor(Date.now()/1e3))}var pe={s:Be,ms:$e,us:Ie,ns:le,seconds:Be,millis:$e,micros:Ie,nanos:le},ce={s:t=>`${Math.floor(t.getTime()/1e3)}`,ms:t=>`${t.getTime()}`,us:t=>`${t.getTime()}000`,ns:t=>`${t.getTime()}000000`};function me(t){return t===void 0?le():typeof t=="string"?t.length>0?t:void 0:t instanceof Date?`${t.getTime()}000000`:String(typeof t=="number"?Math.floor(t):t)}var Ve={error(t,e){console.error("ERROR: "+t,e||"")},warn(t,e){console.warn("WARN: "+t,e||"")}},k=Ve,h={error(t,e){k.error(t,e)},warn(t,e){k.warn(t,e)}};function mt(t){let e=k;return k=t,e}var A=Symbol("FLUX_VALUE"),g=class{constructor(e){this.fluxValue=e}toString(){return this.fluxValue}[A](){return this.fluxValue}};function dt(t){return typeof t=="object"&&typeof t[A]=="function"}function D(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 ht(t){return new g(`"${D(t)}"`)}function he(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 gt(t){return new g(he(t))}function ge(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 yt(t){return new g(ge(t))}function bt(t){return`time(v: "${D(t)}")`}function xt(t){return new g(bt(t))}function Tt(t){return new g(`duration(v: "${D(t)}")`)}function Me(t){return t instanceof RegExp?t.toString():new RegExp(t).toString()}function Rt(t){return new g(Me(t))}function Ct(t){return t==="true"||t==="false"?new g(t):new g((!!t).toString())}function de(t){return new g(String(t))}function N(t){if(t===void 0)return"";if(t===null)return"null";if(typeof t=="boolean")return t.toString();if(typeof t=="string")return`"${D(t)}"`;if(typeof t=="number")return Number.isSafeInteger(t)?ge(t):he(t);if(typeof t=="object"){if(typeof t[A]=="function")return t[A]();if(t instanceof Date)return t.toISOString();if(t instanceof RegExp)return Me(t);if(Array.isArray(t))return`[${t.map(N).join(",")}]`}else if(typeof t=="bigint")return`${t}.0`;return N(t.toString())}function wt(t,...e){if(t.length==1&&e.length===0)return de(t[0]);let r=new Array(t.length+e.length),n=0;for(let i=0;i<t.length;i++){let o=t[i];if(r[n++]=o,i<e.length){let s=e[i],u;if(o.endsWith('"')&&i+1<t.length&&t[i+1].startsWith('"'))u=D(s);else if(u=N(s),u===""&&!dt(s))throw new Error(`Unsupported parameter literal '${s}' at index: ${i}, type: ${typeof s}`);r[n++]=u}else if(i<t.length-1)throw new Error("Too few parameters supplied!")}return de(r.join(""))}var ye=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 o=n.charCodeAt(i);if(o<48||o>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]=R.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(s=>{if(s){let u=this.fields[s];r.length>0&&(r+=","),r+=`${R.tag(s)}=${u}`}}),r.length===0)return;let n="",i=e&&e.defaultTags?c(c({},e.defaultTags),this.tags):this.tags;Object.keys(i).sort().forEach(s=>{if(s){let u=i[s];u&&(n+=",",n+=`${R.tag(s)}=${R.tag(u)}`)}});let o=this.time;return e&&e.convertTime?o=e.convertTime(o):o=me(o),`${R.measurement(this.name)}${n} ${r}${o!==void 0?" "+o:""}`}toString(){let e=this.toLineProtocol(void 0);return e||`invalid point: ${JSON.stringify(this,void 0)}`}};var be=class{constructor(e){this.options=c(c({},se),e),this.success()}nextDelay(e,r){let n=K(e);if(n&&n>0)return n+Math.round(Math.random()*this.options.retryJitter);if(r&&r>0){if(this.options.randomRetry){let o=Math.max(this.options.minRetryDelay,1),s=o*this.options.exponentialBase;for(let u=1;u<r;u++)if(o=s,s=s*this.options.exponentialBase,s>=this.options.maxRetryDelay){s=this.options.maxRetryDelay;break}return o+Math.round(Math.random()*(s-o)+Math.random()*this.options.retryJitter)}let i=Math.max(this.options.minRetryDelay,1);for(let o=1;o<r;o++)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 ke(t){return new be(t)}function St(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 P=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 o=Date.now()+n;if(i<o&&(o=i),this.first&&this.size+e.length>this.maxLines){let p=this.size,a=p*.7;do{let[f,m]=St(this.first);this.size-=f.lines.length,m?m.next=f.next:(this.first=f.next,this.first&&this.scheduleRetry(this.first.retryTime-Date.now())),f.next=void 0,this.onShrink(f)}while(this.first&&this.size+e.length>a);h.error(`RetryBuffer: ${p-this.size} oldest lines removed to keep buffer size under the limit of ${this.maxLines} lines.`)}let s={lines:e,retryCount:r,retryTime:o,expires:i},u=this.first,l;for(;;){if(!u||u.retryTime>o){s.next=u,l?l.next=s:(this.first=s,this.scheduleRetry(o-Date.now()));break}l=u,u=u.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 $(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 xe(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 Te=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=xe(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}},E=class{constructor(e,r,n,i,o){this.transport=e;this.closed=!1;this._timeoutHandle=void 0;this.path=`/api/v2/write?org=${encodeURIComponent(r)}&bucket=${encodeURIComponent(n)}&precision=${i}`,o!=null&&o.consistency&&(this.path+=`&consistency=${encodeURIComponent(o.consistency)}`),this.writeOptions=c(c({},oe),o),this.currentTime=pe[i],this.dateToProtocolTimestamp=ce[i],this.writeOptions.defaultTags&&this.useDefaultTags(this.writeOptions.defaultTags),this.sendOptions={method:"POST",headers:c({"content-type":"text/plain; charset=utf-8"},o==null?void 0:o.headers),gzipThreshold:this.writeOptions.gzipThreshold};let s=()=>{this.writeOptions.flushInterval>0&&(this._clearFlushTimeout(),this.closed||(this._timeoutHandle=setTimeout(()=>this.sendBatch(this.writeBuffer.reset(),this.writeOptions.maxRetries).catch(u=>{}),this.writeOptions.flushInterval)))};this.writeBuffer=new Te(this.writeOptions.batchSize,this.writeOptions.maxBatchBytes,u=>(this._clearFlushTimeout(),this.sendBatch(u,this.writeOptions.maxRetries)),s),this.sendBatch=this.sendBatch.bind(this),this.retryStrategy=ke(this.writeOptions),this.retryBuffer=new P(this.writeOptions.maxBufferLines,this.sendBatch,this.writeOptions.writeRetrySkipped)}sendBatch(e,r,n=Date.now()+this.writeOptions.maxRetryTime){let i=this,o=i.writeOptions.maxRetries+1-r;if(!this.closed&&e.length>0){if(n<=Date.now()){let s=new Error("Max retry time exceeded."),u=i.writeOptions.writeFailed.call(i,s,e,o,n);return u||(h.error(`Write to InfluxDB failed (attempt: ${o}).`,s),Promise.reject(s))}return new Promise((s,u)=>{let l,p={responseStarted(a,f){l=f},error(a){let f=i.writeOptions.writeFailed.call(i,a,e,o,n);if(f){f.then(s,u);return}if(a instanceof d&&a.json&&typeof a.json.error=="string"&&a.json.error.includes("hinted handoff queue not empty")){h.warn("Write to InfluxDB returns: "+a.json.error),l=204,p.complete();return}if(!i.closed&&r>0&&(!(a instanceof d)||a.statusCode>=429)){h.warn(`Write to InfluxDB failed (attempt: ${o}).`,a),i.retryBuffer.addLines(e,r-1,i.retryStrategy.nextDelay(a,o),n),u(a);return}h.error("Write to InfluxDB failed.",a),u(a)},complete(){if(l==204||l==null)i.writeOptions.writeSuccess.call(i,e),i.retryStrategy.success(),s();else{let a=`204 HTTP response status code expected, but ${l} returned`,f=new d(l,a,void 0,"0");f.message=a,p.error(f)}}};this.transport.send(this.path,e.join(`
|
|
5
|
+
`),this.sendOptions,p)})}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 $(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&&h.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)}};var we=require("url"),He=Q(require("http")),qe=Q(require("https")),W=require("buffer");var Re=require("buffer"),Ot={concat(t,e){return Re.Buffer.concat([t,e])},toUtf8String(t,e,r){return t.toString("utf-8",e,r)},copy(t,e,r){let n=Re.Buffer.allocUnsafe(r-e);return t.copy(n,0,e,r),n}},Ne=Ot;var F=Q(require("zlib"));function Ce(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}var We="1.31.0.nightly";var vt={flush:F.default.constants.Z_SYNC_FLUSH,finishFlush:F.default.constants.Z_SYNC_FLUSH},At=W.Buffer.allocUnsafe(0),Se=class{constructor(){this.cancelled=!1}cancel(){this.cancelled=!0,this.resume&&(this.resume(),this.resume=void 0)}isCancelled(){return this.cancelled}},Oe=class{constructor(e){this.chunkCombiner=Ne;var p,a,f,m,b,_,ve;let l=e,{url:r,proxyUrl:n,token:i,transportOptions:o}=l,s=Ee(l,["url","proxyUrl","token","transportOptions"]),u=(0,we.parse)(n||r);if(this.token=i,this.defaultOptions=j(c(c(c({},ie),s),o),{port:u.port,protocol:u.protocol,hostname:u.hostname}),this.contextPath=n?r:(p=u.path)!=null?p:"",this.contextPath.endsWith("/")&&(this.contextPath=this.contextPath.substring(0,this.contextPath.length-1)),Object.keys(this.defaultOptions).forEach(Ae=>this.defaultOptions[Ae]===void 0&&delete this.defaultOptions[Ae]),this.contextPath.endsWith("/api/v2")&&(h.warn(`Please remove '/api/v2' context path from InfluxDB base url, using ${u.protocol}//${u.hostname}:${u.port} !`),this.contextPath=""),u.protocol==="http:")this.requestApi=(m=(f=(a=this.defaultOptions["follow-redirects"])==null?void 0:a.http)==null?void 0:f.request)!=null?m:He.request;else if(u.protocol==="https:")this.requestApi=(ve=(_=(b=this.defaultOptions["follow-redirects"])==null?void 0:b.https)==null?void 0:_.request)!=null?ve:qe.request;else throw new Error(`Unsupported protocol "${u.protocol} in URL: "${e.url}"`);this.headers=c({"User-Agent":`influxdb-client-js/${We}`},e.headers),n&&(this.headers.Host=(0,we.parse)(r).host)}send(e,r,n,i){let o=new Se;i&&i.useCancellable&&i.useCancellable(o),this.createRequestMessage(e,r,n).then(s=>{this._request(s,o,i)},s=>(i==null?void 0:i.error)&&i.error(s))}request(e,r,n,i){r?typeof r!="string"&&(r=JSON.stringify(r)):r="";let o=At,s,u;return new Promise((l,p)=>{this.send(e,r,n,{responseStarted(a,f){i&&i(a,f),s=String(a["content-type"]),u=f},next:a=>{o=W.Buffer.concat([o,a])},complete:()=>{var f,m;let a=(m=(f=n.headers)==null?void 0:f.accept)!=null?m:s;try{u===204&&l(void 0),a.includes("json")?o.length?l(JSON.parse(o.toString("utf8"))):l(void 0):a.includes("text")||a.startsWith("application/csv")?l(o.toString("utf8")):l(o)}catch(b){p(b)}},error:a=>{p(a)}})})}createRequestMessage(e,r,n){let i=W.Buffer.from(r,"utf-8"),o=c({"content-type":"application/json; charset=utf-8"},this.headers);this.token&&(o.authorization="Token "+this.token);let s=Promise.resolve(i),u=j(c({},this.defaultOptions),{path:this.contextPath+e,method:n.method,headers:c(c({},o),n.headers)});return n.gzipThreshold!==void 0&&n.gzipThreshold<i.length&&(s=s.then(l=>new Promise((p,a)=>{F.default.gzip(l,(f,m)=>f?a(f):(u.headers["content-encoding"]="gzip",p(m)))}))),s.then(l=>(u.body=l,u.headers["content-length"]=l.length,u))}_request(e,r,n){let i=Ce(n);if(r.isCancelled()){i.complete();return}let o=this.requestApi(e,s=>{var a;if(r.isCancelled()){s.resume(),i.complete();return}s.on("aborted",()=>{i.error(new T)}),s.on("error",i.error),i.responseStarted(s.headers,s.statusCode);let u=(a=s.statusCode)!=null?a:600,l=s.headers["content-encoding"],p;if(l==="gzip"?(p=F.default.createGunzip(vt),p.on("error",i.error),s.pipe(p)):p=s,u>=300){let f="",m=String(s.headers["content-type"]).startsWith("application/json");p.on("data",b=>{f+=b.toString(),!m&&f.length>1e3&&(f=f.slice(0,1e3),s.resume())}),p.on("end",()=>{f===""&&!!s.headers["x-influxdb-error"]&&(f=s.headers["x-influxdb-error"].toString()),i.error(new d(u,s.statusMessage,f,s.headers["retry-after"],s.headers["content-type"]))})}else p.on("data",f=>{if(r.isCancelled())s.resume();else if(i.next(f)===!1){if(!i.useResume){i.error(new Error("Unable to pause, useResume is not configured!")),s.resume();return}s.pause();let m=()=>{s.resume()};r.resume=m,i.useResume(m)}}),p.on("end",i.complete)});typeof o.setTimeout=="function"&&e.timeout&&o.setTimeout(e.timeout),o.on("timeout",()=>{i.error(new x)}),o.on("error",s=>{i.error(s)}),e.body&&o.write(e.body),o.end()}},je=Oe;var Qe={header:!0,delimiter:",",quoteChar:'"',commentPrefix:"#",annotations:["datatype","group","default"]},L=class{constructor(e,r,n){this.transport=e;this.createCSVResponse=r;this.options=typeof n=="string"?{org:n}:n}with(e){return new L(this.transport,this.createCSVResponse,c(c({},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:o}=this.options;return this.transport.request(`/api/v2/query?org=${encodeURIComponent(r)}`,JSON.stringify(this.decorateRequest({query:e.toString(),dialect:Qe,type:n})),{method:"POST",headers:c({accept:"text/csv","accept-encoding":i?"gzip":"identity","content-type":"application/json; encoding=utf-8"},o)})}createExecutor(e){let{org:r,type:n,gzip:i,headers:o}=this.options;return s=>{this.transport.send(`/api/v2/query?org=${encodeURIComponent(r)}`,JSON.stringify(this.decorateRequest({query:e.toString(),dialect:Qe,type:n})),{method:"POST",headers:c({"content-type":"application/json; encoding=utf-8","accept-encoding":i?"gzip":"identity"},o)},s)}}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}},Je=L;function Dt(t,e){return e.toObject(t)}var H=class{constructor(e,r){this.executor=e;this.chunkCombiner=r}lines(){return new S(this.executor,e=>C(e,this.chunkCombiner))}rows(){return new S(this.executor,e=>C(z({next(r,n){e.next({values:r,tableMeta:n})},error(r){e.error(r)},complete(){e.complete()}}),this.chunkCombiner))}consumeLines(e){this.executor(C(e,this.chunkCombiner))}consumeRows(e){this.executor(C(z(e),this.chunkCombiner))}collectRows(e=Dt){let r=[];return new Promise((n,i)=>{this.consumeRows({next(o,s){let u=e.call(this,o,s);u!==void 0&&r.push(u)},error(o){i(o)},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 U=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 y("No url or configuration specified!");let r=this._options.url;if(typeof r!="string")throw new y("No url specified!");r.endsWith("/")&&(this._options.url=r.substring(0,r.length-1)),this.transport=(n=this._options.transport)!=null?n:new je(this._options),this.processCSVResponse=i=>new H(i,this.transport.chunkCombiner)}getWriteApi(e,r,n="ns",i){return new E(this.transport,e,r,n,i!=null?i:this._options.writeOptions)}getQueryApi(e){return new Je(this.transport,this.processCSVResponse,e)}};0&&(module.exports={AbortError,DEFAULT_ConnectionOptions,DEFAULT_RetryDelayStrategyOptions,DEFAULT_WriteOptions,FLUX_VALUE,HttpError,IllegalArgumentError,InfluxDB,LineSplitter,Log,Point,RequestTimedOutError,UNKNOWN_COLUMN,canRetryHttpCall,chunksToLines,consoleLogger,convertTimeToNanos,createFluxTableColumn,createFluxTableMetaData,createTextDecoderCombiner,currentTime,dateToProtocolTimestamp,escape,flux,fluxBool,fluxDateTime,fluxDuration,fluxExpression,fluxFloat,fluxInteger,fluxRegExp,fluxString,getRetryDelay,isStatusCodeRetriable,linesToTables,newFluxTableColumn,sanitizeFloat,sanitizeInteger,serializeDateTimeAsDate,serializeDateTimeAsNumber,serializeDateTimeAsString,setLogger,stringToLines,symbolObservable,toFluxValue,typeSerializers,useProcessHrtime});
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.gz
CHANGED
|
Binary file
|