@influxdata/influxdb-client 1.31.0 → 1.32.0-nightly.3012

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.
Binary file
Binary file
package/dist/index.js CHANGED
@@ -2,5 +2,5 @@
2
2
  \r `,["\\,","\\ ","\\n","\\r","\\t"]),quoted:ct('"\\',['\\"',"\\\\"]),tag:ae(`, =
3
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
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).catch(()=>{}).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";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});
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.32.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