@influxdata/influxdb-client 1.26.0-nightly.2004 → 1.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/impl/browser/FetchTransport.d.ts.map +1 -1
- package/dist/impl/version.d.ts +1 -1
- package/dist/impl/version.d.ts.map +1 -1
- package/dist/index.browser.js +2 -2
- package/dist/index.browser.js.gz +0 -0
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.gz +0 -0
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.gz +0 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.gz +0 -0
- package/dist/index.mjs.map +1 -1
- package/dist/influxdb.js +2 -2
- package/dist/influxdb.js.gz +0 -0
- package/dist/influxdb.js.map +1 -1
- package/dist/influxdb.min.js +1 -1
- package/dist/influxdb.min.js.gz +0 -0
- package/dist/influxdb.min.js.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -12,5 +12,5 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
12
12
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
13
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
***************************************************************************** */function gt(t,e,r,s){return new(r||(r=Promise))((function(n,i){function o(t){try{a(s.next(t))}catch(t){i(t)}}function l(t){try{a(s.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,l)}a((s=s.apply(t,e||[])).next())}))}class mt{constructor(t){this.options=Object.assign(Object.assign({},B),t),this.success()}nextDelay(t,e){const r=x(t);if(r&&r>0)return r+Math.round(Math.random()*this.options.retryJitter);if(e&&e>0){if(this.options.randomRetry){let t=Math.max(this.options.minRetryDelay,1),r=t*this.options.exponentialBase;for(let s=1;s<e;s++)if(t=r,r*=this.options.exponentialBase,r>=this.options.maxRetryDelay){r=this.options.maxRetryDelay;break}return t+Math.round(Math.random()*(r-t)+Math.random()*this.options.retryJitter)}let t=Math.max(this.options.minRetryDelay,1);for(let r=1;r<e;r++)if(t*=this.options.exponentialBase,t>=this.options.maxRetryDelay){t=this.options.maxRetryDelay;break}return t+Math.round(Math.random()*this.options.retryJitter)}return this.currentDelay?this.currentDelay=Math.min(Math.max(this.currentDelay*this.options.exponentialBase,1)+Math.round(Math.random()*this.options.retryJitter),this.options.maxRetryDelay):this.currentDelay=this.options.minRetryDelay+Math.round(Math.random()*this.options.retryJitter),this.currentDelay}success(){this.currentDelay=void 0}}class yt{constructor(t,e){this.maxLines=t,this.retryLines=e,this.size=0,this.nextRetryTime=0,this.closed=!1,this._timeoutHandle=void 0}addLines(t,e,r,s){if(this.closed)return;if(!t.length)return;let n=Date.now()+r;if(s<n&&(r=s-Date.now(),n=s),n>this.nextRetryTime&&(this.nextRetryTime=n),this.first&&this.size+t.length>this.maxLines){const e=this.size,r=.7*e;do{const t=this.first.next;this.size-=this.first.lines.length,this.first.next=void 0,this.first=t,this.first||(this.last=void 0)}while(this.first&&this.size+t.length>r);X.error(`RetryBuffer: ${e-this.size} oldest lines removed to keep buffer size under the limit of ${this.maxLines} lines`)}const i={lines:t,retryCount:e,expires:s};this.last?(this.last.next=i,this.last=i):(this.first=i,this.last=i,this.scheduleRetry(r)),this.size+=t.length}removeLines(){if(this.first){const t=this.first;return this.first=this.first.next,t.next=void 0,this.size-=t.lines.length,this.first||(this.last=void 0),t}}scheduleRetry(t){this._timeoutHandle=setTimeout((()=>{const t=this.removeLines();t?this.retryLines(t.lines,t.retryCount,t.expires).then((()=>{this.scheduleRetry(1)})).catch((t=>{this.scheduleRetry(this.nextRetryTime-Date.now())})):this._timeoutHandle=void 0}),Math.max(t,0))}flush(){return gt(this,void 0,void 0,(function*(){let t;for(;t=this.removeLines();)yield this.retryLines(t.lines,t.retryCount,t.expires)}))}close(){return this._timeoutHandle&&(clearTimeout(this._timeoutHandle),this._timeoutHandle=void 0),this.closed=!0,this.size}}class wt{constructor(t,e,r,s){this.maxChunkRecords=t,this.maxBatchBytes=e,this.flushFn=r,this.scheduleSend=s,this.length=0,this.bytes=-1,this.lines=new Array(t)}add(t){const e=function(t){let e=t.length;for(let r=0;r<t.length;r++){const s=t.charCodeAt(r);s<128||(s>=128&&s<=2047?e++:s>=2048&&s<=65535?s>=55296&&s<=57343?e++:e+=2:e+=3)}return e}(t);0===this.length?this.scheduleSend():this.bytes+e+1>=this.maxBatchBytes&&this.flush().catch((t=>{})),this.lines[this.length]=t,this.length++,this.bytes+=e+1,(this.length>=this.maxChunkRecords||this.bytes>=this.maxBatchBytes)&&this.flush().catch((t=>{}))}flush(){const t=this.reset();return t.length>0?this.flushFn(t):Promise.resolve()}reset(){const t=this.lines.slice(0,this.length);return this.length=0,this.bytes=-1,t}}class bt{constructor(t,e,r,s,n){this.transport=t,this.closed=!1,this._timeoutHandle=void 0,this.httpPath=`/api/v2/write?org=${encodeURIComponent(e)}&bucket=${encodeURIComponent(r)}&precision=${s}`,(null==n?void 0:n.consistency)&&(this.httpPath+=`&consistency=${encodeURIComponent(n.consistency)}`),this.writeOptions=Object.assign(Object.assign({},P),n),this.currentTime=H[s],this.dateToProtocolTimestamp=W[s],this.writeOptions.defaultTags&&this.useDefaultTags(this.writeOptions.defaultTags),this.sendOptions={method:"POST",headers:Object.assign({"content-type":"text/plain; charset=utf-8"},null==n?void 0:n.headers),gzipThreshold:this.writeOptions.gzipThreshold};var i;this.writeBuffer=new wt(this.writeOptions.batchSize,this.writeOptions.maxBatchBytes,(t=>(this._clearFlushTimeout(),this.sendBatch(t,this.writeOptions.maxRetries))),(()=>{this.writeOptions.flushInterval>0&&(this._clearFlushTimeout(),this.closed||(this._timeoutHandle=setTimeout((()=>this.sendBatch(this.writeBuffer.reset(),this.writeOptions.maxRetries).catch((t=>{}))),this.writeOptions.flushInterval)))})),this.sendBatch=this.sendBatch.bind(this),this.retryStrategy=(i=this.writeOptions,new mt(i)),this.retryBuffer=new yt(this.writeOptions.maxBufferLines,this.sendBatch)}sendBatch(t,e,r=Date.now()+this.writeOptions.maxRetryTime){const s=this,n=s.writeOptions.maxRetries+1-e;if(!this.closed&&t.length>0){if(r<=Date.now()){const e=new Error("Max retry time exceeded."),i=s.writeOptions.writeFailed.call(s,e,t,n,r);return i||(X.error(`Write to InfluxDB failed (attempt: ${n}).`,e),Promise.reject(e))}return new Promise(((i,o)=>{let l;const a={responseStarted(t,e){l=e},error(l){const a=s.writeOptions.writeFailed.call(s,l,t,n,r);if(a)a.then(i,o);else{if(!s.closed&&e>0&&(!(l instanceof y)||l.statusCode>=429))return X.warn(`Write to InfluxDB failed (attempt: ${n}).`,l),s.retryBuffer.addLines(t,e-1,s.retryStrategy.nextDelay(l,n),r),void o(l);X.error("Write to InfluxDB failed.",l),o(l)}},complete(){if(204==l||null==l)s.writeOptions.writeSuccess.call(s,t),s.retryStrategy.success(),i();else{const t=`204 HTTP response status code expected, but ${l} returned`,e=new y(l,t,void 0,"0");e.message=t,a.error(e)}}};this.transport.send(this.httpPath,t.join("\n"),this.sendOptions,a)}))}return Promise.resolve()}_clearFlushTimeout(){void 0!==this._timeoutHandle&&(clearTimeout(this._timeoutHandle),this._timeoutHandle=void 0)}writeRecord(t){if(this.closed)throw new Error("writeApi: already closed!");this.writeBuffer.add(t)}writeRecords(t){if(this.closed)throw new Error("writeApi: already closed!");for(let e=0;e<t.length;e++)this.writeBuffer.add(t[e])}writePoint(t){if(this.closed)throw new Error("writeApi: already closed!");const e=t.toLineProtocol(this);e&&this.writeBuffer.add(e)}writePoints(t){if(this.closed)throw new Error("writeApi: already closed!");for(let e=0;e<t.length;e++){const r=t[e].toLineProtocol(this);r&&this.writeBuffer.add(r)}}flush(t){return gt(this,void 0,void 0,(function*(){if(yield this.writeBuffer.flush(),t)return yield this.retryBuffer.flush()}))}close(){return this.writeBuffer.flush().finally((()=>{const t=this.retryBuffer.close();t&&X.error(`Retry buffer closed with ${t} items that were not written to InfluxDB!`,null),this.closed=!0}))}dispose(){return this._clearFlushTimeout(),this.closed=!0,this.retryBuffer.close()+this.writeBuffer.length}useDefaultTags(t){return this.defaultTags=t,this}convertTime(t){return void 0===t?this.currentTime():"string"==typeof t?t.length>0?t:void 0:t instanceof Date?this.dateToProtocolTimestamp(t):String("number"==typeof t?Math.floor(t):t)}}const xt={concat:(t,e)=>s.concat([t,e]),toUtf8String:(t,e,r)=>t.toString("utf-8",e,r),copy(t,e,r){const n=s.allocUnsafe(r-e);return t.copy(n,0,e,r),n}};const vt={flush:n.constants.Z_SYNC_FLUSH,finishFlush:n.constants.Z_SYNC_FLUSH},Ot=s.allocUnsafe(0);class St{constructor(){this.cancelled=!1}cancel(){this.cancelled=!0}isCancelled(){return this.cancelled}}class Rt{constructor(s){var n,i,o,l,a,h,c;this.chunkCombiner=xt;const{url:u,proxyUrl:f,token:d,transportOptions:p}=s,g=function(t,e){var r={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.indexOf(s)<0&&(r[s]=t[s]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(t);n<s.length;n++)e.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(t,s[n])&&(r[s[n]]=t[s[n]])}return r}(s,["url","proxyUrl","token","transportOptions"]),m=t(f||u);if(this.token=d,this.defaultOptions=Object.assign(Object.assign(Object.assign(Object.assign({},D),g),p),{port:m.port,protocol:m.protocol,hostname:m.hostname}),this.contextPath=f?u:null!==(n=m.path)&&void 0!==n?n:"",this.contextPath.endsWith("/")&&(this.contextPath=this.contextPath.substring(0,this.contextPath.length-1)),Object.keys(this.defaultOptions).forEach((t=>void 0===this.defaultOptions[t]&&delete this.defaultOptions[t])),this.contextPath.endsWith("/api/v2")&&(X.warn(`Please remove '/api/v2' context path from InfluxDB base url, using ${m.protocol}//${m.hostname}:${m.port} !`),this.contextPath=""),"http:"===m.protocol)this.requestApi=null!==(l=null===(o=null===(i=this.defaultOptions["follow-redirects"])||void 0===i?void 0:i.http)||void 0===o?void 0:o.request)&&void 0!==l?l:e.request;else{if("https:"!==m.protocol)throw new Error(`Unsupported protocol "${m.protocol} in URL: "${s.url}"`);this.requestApi=null!==(c=null===(h=null===(a=this.defaultOptions["follow-redirects"])||void 0===a?void 0:a.https)||void 0===h?void 0:h.request)&&void 0!==c?c:r.request}this.headers=Object.assign({"User-Agent":"influxdb-client-js/1.26.0.nightly"},s.headers),f&&(this.headers.Host=t(u).host)}send(t,e,r,s){const n=new St;s&&s.useCancellable&&s.useCancellable(n),this.createRequestMessage(t,e,r).then((t=>{this._request(t,n,s)}),(t=>(null==s?void 0:s.error)&&s.error(t)))}request(t,e,r,n){e?"string"!=typeof e&&(e=JSON.stringify(e)):e="";let i,o,l=Ot;return new Promise(((a,h)=>{this.send(t,e,r,{responseStarted(t,e){n&&n(t,e),i=String(t["content-type"]),o=e},next:t=>{l=s.concat([l,t])},complete:()=>{var t,e;const s=null!==(e=null===(t=r.headers)||void 0===t?void 0:t.accept)&&void 0!==e?e:i;try{204===o&&a(void 0),s.includes("json")?l.length?a(JSON.parse(l.toString("utf8"))):a(void 0):s.includes("text")||s.startsWith("application/csv")?a(l.toString("utf8")):a(l)}catch(t){h(t)}},error:t=>{h(t)}})}))}createRequestMessage(t,e,r){const i=s.from(e,"utf-8"),o=Object.assign({"content-type":"application/json; charset=utf-8"},this.headers);this.token&&(o.authorization="Token "+this.token);let l=Promise.resolve(i);const a=Object.assign(Object.assign({},this.defaultOptions),{path:this.contextPath+t,method:r.method,headers:Object.assign(Object.assign({},o),r.headers)});return void 0!==r.gzipThreshold&&r.gzipThreshold<i.length&&(l=l.then((t=>new Promise(((e,r)=>{n.gzip(t,((t,s)=>t?r(t):(a.headers["content-encoding"]="gzip",e(s))))}))))),l.then((t=>(a.body=t,a.headers["content-length"]=t.length,a)))}_request(t,e,r){const s=function(t={}){let e=0;return{next:r=>{0===e&&t.next&&null!=r&&t.next(r)},error:r=>{0===e&&(e=1,t.error&&t.error(r))},complete:()=>{0===e&&(e=2,t.complete&&t.complete())},responseStarted:(e,r)=>{t.responseStarted&&t.responseStarted(e,r)}}}(r);if(e.isCancelled())return void s.complete();const i=this.requestApi(t,(t=>{var r;if(e.isCancelled())return t.resume(),void s.complete();t.on("aborted",(()=>{s.error(new O)})),t.on("error",s.error),s.responseStarted(t.headers,t.statusCode);const i=null!==(r=t.statusCode)&&void 0!==r?r:600;let o;if("gzip"===t.headers["content-encoding"]?(o=n.createGunzip(vt),o.on("error",s.error),t.pipe(o)):o=t,i>=300){let e="";const r=String(t.headers["content-type"]).startsWith("application/json");o.on("data",(s=>{e+=s.toString(),!r&&e.length>1e3&&(e=e.slice(0,1e3),t.resume())})),o.on("end",(()=>{""===e&&t.headers["x-influxdb-error"]&&(e=t.headers["x-influxdb-error"].toString()),s.error(new y(i,t.statusMessage,e,t.headers["retry-after"],t.headers["content-type"]))}))}else o.on("data",(r=>{e.isCancelled()?t.resume():s.next(r)})),o.on("end",s.complete)}));"function"==typeof i.setTimeout&&t.timeout&&i.setTimeout(t.timeout),i.on("timeout",(()=>{s.error(new v)})),i.on("error",(t=>{s.error(t)})),t.body&&i.write(t.body),i.end()}}const Tt={header:!0,delimiter:",",quoteChar:'"',commentPrefix:"#",annotations:["datatype","group","default"]};class $t{constructor(t,e,r){this.transport=t,this.createCSVResponse=e,this.options="string"==typeof r?{org:r}:r}with(t){return new $t(this.transport,this.createCSVResponse,Object.assign(Object.assign({},this.options),t))}response(t){return this.createCSVResponse(this.createExecutor(t))}lines(t){return this.response(t).lines()}rows(t){return this.response(t).rows()}queryLines(t,e){return this.response(t).consumeLines(e)}queryRows(t,e){return this.response(t).consumeRows(e)}collectRows(t,e){return this.response(t).collectRows(e)}collectLines(t){return this.response(t).collectLines()}queryRaw(t){const{org:e,type:r,gzip:s,headers:n}=this.options;return this.transport.request(`/api/v2/query?org=${encodeURIComponent(e)}`,JSON.stringify(this.decorateRequest({query:t.toString(),dialect:Tt,type:r})),{method:"POST",headers:Object.assign({accept:"text/csv","accept-encoding":s?"gzip":"identity","content-type":"application/json; encoding=utf-8"},n)})}createExecutor(t){const{org:e,type:r,gzip:s,headers:n}=this.options;return i=>{this.transport.send(`/api/v2/query?org=${encodeURIComponent(e)}`,JSON.stringify(this.decorateRequest({query:t.toString(),dialect:Tt,type:r})),{method:"POST",headers:Object.assign({"content-type":"application/json; encoding=utf-8","accept-encoding":s?"gzip":"identity"},n)},i)}}decorateRequest(t){var e;return"function"==typeof this.options.now&&(t.now=this.options.now()),t.type=null!==(e=this.options.type)&&void 0!==e?e:"flux",t}}class Ct{constructor(t,e){this.isClosed=!1;try{e({next:e=>{t.next(e)},error:e=>{this.isClosed=!0,t.error(e)},complete:()=>{this.isClosed=!0,t.complete()},useCancellable:t=>{this.cancellable=t}})}catch(e){this.isClosed=!0,t.error(e)}}get closed(){return this.isClosed}unsubscribe(){var t;null===(t=this.cancellable)||void 0===t||t.cancel(),this.isClosed=!0}}function Et(){}class jt{constructor(t,e){this.executor=t,this.decorator=e}subscribe(t,e,r){const s=function(t){const{next:e,error:r,complete:s}=t;return{next:e?e.bind(t):Et,error:r?r.bind(t):Et,complete:s?s.bind(t):Et}}("object"!=typeof t||null===t?{next:t,error:e,complete:r}:t);return new Ct(this.decorator(s),this.executor)}[dt](){return this}}function Dt(t,e){return e.toObject(t)}class Bt{constructor(t,e){this.executor=t,this.chunkCombiner=e}lines(){return new jt(this.executor,(t=>o(t,this.chunkCombiner)))}rows(){return new jt(this.executor,(t=>o(E({next(e,r){t.next({values:e,tableMeta:r})},error(e){t.error(e)},complete(){t.complete()}}),this.chunkCombiner)))}consumeLines(t){this.executor(o(t,this.chunkCombiner))}consumeRows(t){this.executor(o(E(t),this.chunkCombiner))}collectRows(t=Dt){const e=[];return new Promise(((r,s)=>{this.consumeRows({next(r,s){const n=t.call(this,r,s);void 0!==n&&e.push(n)},error(t){s(t)},complete(){r(e)}})}))}collectLines(){const t=[];return new Promise(((e,r)=>{this.consumeLines({next(e){t.push(e)},error(t){r(t)},complete(){e(t)}})}))}}class Pt{constructor(t){var e;if("string"==typeof t)this._options={url:t};else{if(null===t||"object"!=typeof t)throw new m("No url or configuration specified!");this._options=t}const r=this._options.url;if("string"!=typeof r)throw new m("No url specified!");r.endsWith("/")&&(this._options.url=r.substring(0,r.length-1)),this.transport=null!==(e=this._options.transport)&&void 0!==e?e:new Rt(this._options),this.processCSVResponse=t=>new Bt(t,this.transport.chunkCombiner)}getWriteApi(t,e,r="ns",s){return new bt(this.transport,t,e,r,null!=s?s:this._options.writeOptions)}getQueryApi(t){return new $t(this.transport,this.processCSVResponse,t)}}export{O as AbortError,D as DEFAULT_ConnectionOptions,B as DEFAULT_RetryDelayStrategyOptions,P as DEFAULT_WriteOptions,K as FLUX_VALUE,y as HttpError,m as IllegalArgumentError,Pt as InfluxDB,l as LineSplitter,X as Log,pt as Point,v as RequestTimedOutError,u as UNKNOWN_COLUMN,b as canRetryHttpCall,o as chunksToLines,G as consoleLogger,J as convertTimeToNanos,d as createFluxTableColumn,C as createFluxTableMetaData,i as createTextDecoderCombiner,H as currentTime,W as dateToProtocolTimestamp,_ as escape,ft as flux,ht as fluxBool,it as fluxDateTime,ot as fluxDuration,ct as fluxExpression,st as fluxFloat,nt as fluxInteger,at as fluxRegExp,et as fluxString,x as getRetryDelay,g as isStatusCodeRetriable,E as linesToTables,f as newFluxTableColumn,rt as sanitizeFloat,S as serializeDateTimeAsDate,R as serializeDateTimeAsNumber,T as serializeDateTimeAsString,Z as setLogger,j as stringToLines,dt as symbolObservable,ut as toFluxValue,h as typeSerializers,N as useProcessHrtime};
|
|
15
|
+
***************************************************************************** */function gt(t,e,r,s){return new(r||(r=Promise))((function(n,i){function o(t){try{a(s.next(t))}catch(t){i(t)}}function l(t){try{a(s.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,l)}a((s=s.apply(t,e||[])).next())}))}class mt{constructor(t){this.options=Object.assign(Object.assign({},B),t),this.success()}nextDelay(t,e){const r=x(t);if(r&&r>0)return r+Math.round(Math.random()*this.options.retryJitter);if(e&&e>0){if(this.options.randomRetry){let t=Math.max(this.options.minRetryDelay,1),r=t*this.options.exponentialBase;for(let s=1;s<e;s++)if(t=r,r*=this.options.exponentialBase,r>=this.options.maxRetryDelay){r=this.options.maxRetryDelay;break}return t+Math.round(Math.random()*(r-t)+Math.random()*this.options.retryJitter)}let t=Math.max(this.options.minRetryDelay,1);for(let r=1;r<e;r++)if(t*=this.options.exponentialBase,t>=this.options.maxRetryDelay){t=this.options.maxRetryDelay;break}return t+Math.round(Math.random()*this.options.retryJitter)}return this.currentDelay?this.currentDelay=Math.min(Math.max(this.currentDelay*this.options.exponentialBase,1)+Math.round(Math.random()*this.options.retryJitter),this.options.maxRetryDelay):this.currentDelay=this.options.minRetryDelay+Math.round(Math.random()*this.options.retryJitter),this.currentDelay}success(){this.currentDelay=void 0}}class yt{constructor(t,e){this.maxLines=t,this.retryLines=e,this.size=0,this.nextRetryTime=0,this.closed=!1,this._timeoutHandle=void 0}addLines(t,e,r,s){if(this.closed)return;if(!t.length)return;let n=Date.now()+r;if(s<n&&(r=s-Date.now(),n=s),n>this.nextRetryTime&&(this.nextRetryTime=n),this.first&&this.size+t.length>this.maxLines){const e=this.size,r=.7*e;do{const t=this.first.next;this.size-=this.first.lines.length,this.first.next=void 0,this.first=t,this.first||(this.last=void 0)}while(this.first&&this.size+t.length>r);X.error(`RetryBuffer: ${e-this.size} oldest lines removed to keep buffer size under the limit of ${this.maxLines} lines`)}const i={lines:t,retryCount:e,expires:s};this.last?(this.last.next=i,this.last=i):(this.first=i,this.last=i,this.scheduleRetry(r)),this.size+=t.length}removeLines(){if(this.first){const t=this.first;return this.first=this.first.next,t.next=void 0,this.size-=t.lines.length,this.first||(this.last=void 0),t}}scheduleRetry(t){this._timeoutHandle=setTimeout((()=>{const t=this.removeLines();t?this.retryLines(t.lines,t.retryCount,t.expires).then((()=>{this.scheduleRetry(1)})).catch((t=>{this.scheduleRetry(this.nextRetryTime-Date.now())})):this._timeoutHandle=void 0}),Math.max(t,0))}flush(){return gt(this,void 0,void 0,(function*(){let t;for(;t=this.removeLines();)yield this.retryLines(t.lines,t.retryCount,t.expires)}))}close(){return this._timeoutHandle&&(clearTimeout(this._timeoutHandle),this._timeoutHandle=void 0),this.closed=!0,this.size}}class wt{constructor(t,e,r,s){this.maxChunkRecords=t,this.maxBatchBytes=e,this.flushFn=r,this.scheduleSend=s,this.length=0,this.bytes=-1,this.lines=new Array(t)}add(t){const e=function(t){let e=t.length;for(let r=0;r<t.length;r++){const s=t.charCodeAt(r);s<128||(s>=128&&s<=2047?e++:s>=2048&&s<=65535?s>=55296&&s<=57343?e++:e+=2:e+=3)}return e}(t);0===this.length?this.scheduleSend():this.bytes+e+1>=this.maxBatchBytes&&this.flush().catch((t=>{})),this.lines[this.length]=t,this.length++,this.bytes+=e+1,(this.length>=this.maxChunkRecords||this.bytes>=this.maxBatchBytes)&&this.flush().catch((t=>{}))}flush(){const t=this.reset();return t.length>0?this.flushFn(t):Promise.resolve()}reset(){const t=this.lines.slice(0,this.length);return this.length=0,this.bytes=-1,t}}class bt{constructor(t,e,r,s,n){this.transport=t,this.closed=!1,this._timeoutHandle=void 0,this.httpPath=`/api/v2/write?org=${encodeURIComponent(e)}&bucket=${encodeURIComponent(r)}&precision=${s}`,(null==n?void 0:n.consistency)&&(this.httpPath+=`&consistency=${encodeURIComponent(n.consistency)}`),this.writeOptions=Object.assign(Object.assign({},P),n),this.currentTime=H[s],this.dateToProtocolTimestamp=W[s],this.writeOptions.defaultTags&&this.useDefaultTags(this.writeOptions.defaultTags),this.sendOptions={method:"POST",headers:Object.assign({"content-type":"text/plain; charset=utf-8"},null==n?void 0:n.headers),gzipThreshold:this.writeOptions.gzipThreshold};var i;this.writeBuffer=new wt(this.writeOptions.batchSize,this.writeOptions.maxBatchBytes,(t=>(this._clearFlushTimeout(),this.sendBatch(t,this.writeOptions.maxRetries))),(()=>{this.writeOptions.flushInterval>0&&(this._clearFlushTimeout(),this.closed||(this._timeoutHandle=setTimeout((()=>this.sendBatch(this.writeBuffer.reset(),this.writeOptions.maxRetries).catch((t=>{}))),this.writeOptions.flushInterval)))})),this.sendBatch=this.sendBatch.bind(this),this.retryStrategy=(i=this.writeOptions,new mt(i)),this.retryBuffer=new yt(this.writeOptions.maxBufferLines,this.sendBatch)}sendBatch(t,e,r=Date.now()+this.writeOptions.maxRetryTime){const s=this,n=s.writeOptions.maxRetries+1-e;if(!this.closed&&t.length>0){if(r<=Date.now()){const e=new Error("Max retry time exceeded."),i=s.writeOptions.writeFailed.call(s,e,t,n,r);return i||(X.error(`Write to InfluxDB failed (attempt: ${n}).`,e),Promise.reject(e))}return new Promise(((i,o)=>{let l;const a={responseStarted(t,e){l=e},error(l){const a=s.writeOptions.writeFailed.call(s,l,t,n,r);if(a)a.then(i,o);else{if(!s.closed&&e>0&&(!(l instanceof y)||l.statusCode>=429))return X.warn(`Write to InfluxDB failed (attempt: ${n}).`,l),s.retryBuffer.addLines(t,e-1,s.retryStrategy.nextDelay(l,n),r),void o(l);X.error("Write to InfluxDB failed.",l),o(l)}},complete(){if(204==l||null==l)s.writeOptions.writeSuccess.call(s,t),s.retryStrategy.success(),i();else{const t=`204 HTTP response status code expected, but ${l} returned`,e=new y(l,t,void 0,"0");e.message=t,a.error(e)}}};this.transport.send(this.httpPath,t.join("\n"),this.sendOptions,a)}))}return Promise.resolve()}_clearFlushTimeout(){void 0!==this._timeoutHandle&&(clearTimeout(this._timeoutHandle),this._timeoutHandle=void 0)}writeRecord(t){if(this.closed)throw new Error("writeApi: already closed!");this.writeBuffer.add(t)}writeRecords(t){if(this.closed)throw new Error("writeApi: already closed!");for(let e=0;e<t.length;e++)this.writeBuffer.add(t[e])}writePoint(t){if(this.closed)throw new Error("writeApi: already closed!");const e=t.toLineProtocol(this);e&&this.writeBuffer.add(e)}writePoints(t){if(this.closed)throw new Error("writeApi: already closed!");for(let e=0;e<t.length;e++){const r=t[e].toLineProtocol(this);r&&this.writeBuffer.add(r)}}flush(t){return gt(this,void 0,void 0,(function*(){if(yield this.writeBuffer.flush(),t)return yield this.retryBuffer.flush()}))}close(){return this.writeBuffer.flush().finally((()=>{const t=this.retryBuffer.close();t&&X.error(`Retry buffer closed with ${t} items that were not written to InfluxDB!`,null),this.closed=!0}))}dispose(){return this._clearFlushTimeout(),this.closed=!0,this.retryBuffer.close()+this.writeBuffer.length}useDefaultTags(t){return this.defaultTags=t,this}convertTime(t){return void 0===t?this.currentTime():"string"==typeof t?t.length>0?t:void 0:t instanceof Date?this.dateToProtocolTimestamp(t):String("number"==typeof t?Math.floor(t):t)}}const xt={concat:(t,e)=>s.concat([t,e]),toUtf8String:(t,e,r)=>t.toString("utf-8",e,r),copy(t,e,r){const n=s.allocUnsafe(r-e);return t.copy(n,0,e,r),n}};const vt={flush:n.constants.Z_SYNC_FLUSH,finishFlush:n.constants.Z_SYNC_FLUSH},Ot=s.allocUnsafe(0);class St{constructor(){this.cancelled=!1}cancel(){this.cancelled=!0}isCancelled(){return this.cancelled}}class Rt{constructor(s){var n,i,o,l,a,h,c;this.chunkCombiner=xt;const{url:u,proxyUrl:f,token:d,transportOptions:p}=s,g=function(t,e){var r={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.indexOf(s)<0&&(r[s]=t[s]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(t);n<s.length;n++)e.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(t,s[n])&&(r[s[n]]=t[s[n]])}return r}(s,["url","proxyUrl","token","transportOptions"]),m=t(f||u);if(this.token=d,this.defaultOptions=Object.assign(Object.assign(Object.assign(Object.assign({},D),g),p),{port:m.port,protocol:m.protocol,hostname:m.hostname}),this.contextPath=f?u:null!==(n=m.path)&&void 0!==n?n:"",this.contextPath.endsWith("/")&&(this.contextPath=this.contextPath.substring(0,this.contextPath.length-1)),Object.keys(this.defaultOptions).forEach((t=>void 0===this.defaultOptions[t]&&delete this.defaultOptions[t])),this.contextPath.endsWith("/api/v2")&&(X.warn(`Please remove '/api/v2' context path from InfluxDB base url, using ${m.protocol}//${m.hostname}:${m.port} !`),this.contextPath=""),"http:"===m.protocol)this.requestApi=null!==(l=null===(o=null===(i=this.defaultOptions["follow-redirects"])||void 0===i?void 0:i.http)||void 0===o?void 0:o.request)&&void 0!==l?l:e.request;else{if("https:"!==m.protocol)throw new Error(`Unsupported protocol "${m.protocol} in URL: "${s.url}"`);this.requestApi=null!==(c=null===(h=null===(a=this.defaultOptions["follow-redirects"])||void 0===a?void 0:a.https)||void 0===h?void 0:h.request)&&void 0!==c?c:r.request}this.headers=Object.assign({"User-Agent":"influxdb-client-js/1.26.0"},s.headers),f&&(this.headers.Host=t(u).host)}send(t,e,r,s){const n=new St;s&&s.useCancellable&&s.useCancellable(n),this.createRequestMessage(t,e,r).then((t=>{this._request(t,n,s)}),(t=>(null==s?void 0:s.error)&&s.error(t)))}request(t,e,r,n){e?"string"!=typeof e&&(e=JSON.stringify(e)):e="";let i,o,l=Ot;return new Promise(((a,h)=>{this.send(t,e,r,{responseStarted(t,e){n&&n(t,e),i=String(t["content-type"]),o=e},next:t=>{l=s.concat([l,t])},complete:()=>{var t,e;const s=null!==(e=null===(t=r.headers)||void 0===t?void 0:t.accept)&&void 0!==e?e:i;try{204===o&&a(void 0),s.includes("json")?l.length?a(JSON.parse(l.toString("utf8"))):a(void 0):s.includes("text")||s.startsWith("application/csv")?a(l.toString("utf8")):a(l)}catch(t){h(t)}},error:t=>{h(t)}})}))}createRequestMessage(t,e,r){const i=s.from(e,"utf-8"),o=Object.assign({"content-type":"application/json; charset=utf-8"},this.headers);this.token&&(o.authorization="Token "+this.token);let l=Promise.resolve(i);const a=Object.assign(Object.assign({},this.defaultOptions),{path:this.contextPath+t,method:r.method,headers:Object.assign(Object.assign({},o),r.headers)});return void 0!==r.gzipThreshold&&r.gzipThreshold<i.length&&(l=l.then((t=>new Promise(((e,r)=>{n.gzip(t,((t,s)=>t?r(t):(a.headers["content-encoding"]="gzip",e(s))))}))))),l.then((t=>(a.body=t,a.headers["content-length"]=t.length,a)))}_request(t,e,r){const s=function(t={}){let e=0;return{next:r=>{0===e&&t.next&&null!=r&&t.next(r)},error:r=>{0===e&&(e=1,t.error&&t.error(r))},complete:()=>{0===e&&(e=2,t.complete&&t.complete())},responseStarted:(e,r)=>{t.responseStarted&&t.responseStarted(e,r)}}}(r);if(e.isCancelled())return void s.complete();const i=this.requestApi(t,(t=>{var r;if(e.isCancelled())return t.resume(),void s.complete();t.on("aborted",(()=>{s.error(new O)})),t.on("error",s.error),s.responseStarted(t.headers,t.statusCode);const i=null!==(r=t.statusCode)&&void 0!==r?r:600;let o;if("gzip"===t.headers["content-encoding"]?(o=n.createGunzip(vt),o.on("error",s.error),t.pipe(o)):o=t,i>=300){let e="";const r=String(t.headers["content-type"]).startsWith("application/json");o.on("data",(s=>{e+=s.toString(),!r&&e.length>1e3&&(e=e.slice(0,1e3),t.resume())})),o.on("end",(()=>{""===e&&t.headers["x-influxdb-error"]&&(e=t.headers["x-influxdb-error"].toString()),s.error(new y(i,t.statusMessage,e,t.headers["retry-after"],t.headers["content-type"]))}))}else o.on("data",(r=>{e.isCancelled()?t.resume():s.next(r)})),o.on("end",s.complete)}));"function"==typeof i.setTimeout&&t.timeout&&i.setTimeout(t.timeout),i.on("timeout",(()=>{s.error(new v)})),i.on("error",(t=>{s.error(t)})),t.body&&i.write(t.body),i.end()}}const Tt={header:!0,delimiter:",",quoteChar:'"',commentPrefix:"#",annotations:["datatype","group","default"]};class $t{constructor(t,e,r){this.transport=t,this.createCSVResponse=e,this.options="string"==typeof r?{org:r}:r}with(t){return new $t(this.transport,this.createCSVResponse,Object.assign(Object.assign({},this.options),t))}response(t){return this.createCSVResponse(this.createExecutor(t))}lines(t){return this.response(t).lines()}rows(t){return this.response(t).rows()}queryLines(t,e){return this.response(t).consumeLines(e)}queryRows(t,e){return this.response(t).consumeRows(e)}collectRows(t,e){return this.response(t).collectRows(e)}collectLines(t){return this.response(t).collectLines()}queryRaw(t){const{org:e,type:r,gzip:s,headers:n}=this.options;return this.transport.request(`/api/v2/query?org=${encodeURIComponent(e)}`,JSON.stringify(this.decorateRequest({query:t.toString(),dialect:Tt,type:r})),{method:"POST",headers:Object.assign({accept:"text/csv","accept-encoding":s?"gzip":"identity","content-type":"application/json; encoding=utf-8"},n)})}createExecutor(t){const{org:e,type:r,gzip:s,headers:n}=this.options;return i=>{this.transport.send(`/api/v2/query?org=${encodeURIComponent(e)}`,JSON.stringify(this.decorateRequest({query:t.toString(),dialect:Tt,type:r})),{method:"POST",headers:Object.assign({"content-type":"application/json; encoding=utf-8","accept-encoding":s?"gzip":"identity"},n)},i)}}decorateRequest(t){var e;return"function"==typeof this.options.now&&(t.now=this.options.now()),t.type=null!==(e=this.options.type)&&void 0!==e?e:"flux",t}}class Ct{constructor(t,e){this.isClosed=!1;try{e({next:e=>{t.next(e)},error:e=>{this.isClosed=!0,t.error(e)},complete:()=>{this.isClosed=!0,t.complete()},useCancellable:t=>{this.cancellable=t}})}catch(e){this.isClosed=!0,t.error(e)}}get closed(){return this.isClosed}unsubscribe(){var t;null===(t=this.cancellable)||void 0===t||t.cancel(),this.isClosed=!0}}function Et(){}class jt{constructor(t,e){this.executor=t,this.decorator=e}subscribe(t,e,r){const s=function(t){const{next:e,error:r,complete:s}=t;return{next:e?e.bind(t):Et,error:r?r.bind(t):Et,complete:s?s.bind(t):Et}}("object"!=typeof t||null===t?{next:t,error:e,complete:r}:t);return new Ct(this.decorator(s),this.executor)}[dt](){return this}}function Dt(t,e){return e.toObject(t)}class Bt{constructor(t,e){this.executor=t,this.chunkCombiner=e}lines(){return new jt(this.executor,(t=>o(t,this.chunkCombiner)))}rows(){return new jt(this.executor,(t=>o(E({next(e,r){t.next({values:e,tableMeta:r})},error(e){t.error(e)},complete(){t.complete()}}),this.chunkCombiner)))}consumeLines(t){this.executor(o(t,this.chunkCombiner))}consumeRows(t){this.executor(o(E(t),this.chunkCombiner))}collectRows(t=Dt){const e=[];return new Promise(((r,s)=>{this.consumeRows({next(r,s){const n=t.call(this,r,s);void 0!==n&&e.push(n)},error(t){s(t)},complete(){r(e)}})}))}collectLines(){const t=[];return new Promise(((e,r)=>{this.consumeLines({next(e){t.push(e)},error(t){r(t)},complete(){e(t)}})}))}}class Pt{constructor(t){var e;if("string"==typeof t)this._options={url:t};else{if(null===t||"object"!=typeof t)throw new m("No url or configuration specified!");this._options=t}const r=this._options.url;if("string"!=typeof r)throw new m("No url specified!");r.endsWith("/")&&(this._options.url=r.substring(0,r.length-1)),this.transport=null!==(e=this._options.transport)&&void 0!==e?e:new Rt(this._options),this.processCSVResponse=t=>new Bt(t,this.transport.chunkCombiner)}getWriteApi(t,e,r="ns",s){return new bt(this.transport,t,e,r,null!=s?s:this._options.writeOptions)}getQueryApi(t){return new $t(this.transport,this.processCSVResponse,t)}}export{O as AbortError,D as DEFAULT_ConnectionOptions,B as DEFAULT_RetryDelayStrategyOptions,P as DEFAULT_WriteOptions,K as FLUX_VALUE,y as HttpError,m as IllegalArgumentError,Pt as InfluxDB,l as LineSplitter,X as Log,pt as Point,v as RequestTimedOutError,u as UNKNOWN_COLUMN,b as canRetryHttpCall,o as chunksToLines,G as consoleLogger,J as convertTimeToNanos,d as createFluxTableColumn,C as createFluxTableMetaData,i as createTextDecoderCombiner,H as currentTime,W as dateToProtocolTimestamp,_ as escape,ft as flux,ht as fluxBool,it as fluxDateTime,ot as fluxDuration,ct as fluxExpression,st as fluxFloat,nt as fluxInteger,at as fluxRegExp,et as fluxString,x as getRetryDelay,g as isStatusCodeRetriable,E as linesToTables,f as newFluxTableColumn,rt as sanitizeFloat,S as serializeDateTimeAsDate,R as serializeDateTimeAsNumber,T as serializeDateTimeAsString,Z as setLogger,j as stringToLines,dt as symbolObservable,ut as toFluxValue,h as typeSerializers,N as useProcessHrtime};
|
|
16
16
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.gz
CHANGED
|
Binary file
|