@influxdata/influxdb-client-browser 1.18.0 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Point.d.ts +3 -0
- package/dist/Point.d.ts.map +1 -1
- package/dist/all.d.ts +3 -0
- package/dist/impl/version.d.ts +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 +2 -2
- package/dist/index.js.gz +0 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.gz +0 -0
- package/dist/index.mjs.map +1 -1
- package/dist/influxdb.js +26 -17
- 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 +3 -3
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("url"),e=require("http"),r=require("https"),s=require("buffer");function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=n(require("zlib"));function o(){const t=new TextDecoder("utf-8");return{concat(t,e){const r=new Uint8Array(t.length+e.length);return r.set(t),r.set(e,t.length),r},copy(t,e,r){const s=new Uint8Array(r-e);return s.set(t.subarray(e,r)),s},toUtf8String:(e,r,s)=>t.decode(e.subarray(r,s))}}function l(t,e){const r=null!=e?e:o();let s,n=!1,i=!1;return{next(e){if(!n)try{!function(e){let o,l=0;for(s?(e=r.concat(s,e),o=s.length):o=0;o<e.length;){const s=e[o];if(10===s){if(!i){const s=o>0&&13===e[o-1]?o-1:o;if(n)return;t.next(r.toUtf8String(e,l,s)),l=o+1}}else 34===s&&(i=!i);o++}s=l<o?r.copy(e,l,o):void 0}(e)}catch(t){this.error(t)}},error(e){n||(n=!0,t.error(e))},complete(){n||(s&&t.next(r.toUtf8String(s,0,s.length)),n=!0,t.complete())},useCancellable(e){if(t.useCancellable){const r=this;t.useCancellable({cancel(){e.cancel(),s=void 0,r.complete()},isCancelled:()=>e.isCancelled()})}}}}class a{constructor(){this._reuse=!1}get reuse(){return this._reuse}set reuse(t){t&&!this.reusedValues&&(this.reusedValues=new Array(10)),this._reuse=t}withReuse(){return this.reuse=!0,this}splitLine(t){if(null==t)return this.lastSplitLength=0,[];let e=0,r=0;const s=this._reuse?this.reusedValues:[];let n=0;for(let i=0;i<t.length;i++){const o=t[i];if(","===o){if(e%2==0){const o=this.getValue(t,r,i,e);this._reuse?s[n++]=o:s.push(o),r=i+1,e=0}}else'"'===o&&e++}const i=this.getValue(t,r,t.length,e);return this._reuse?(s[n]=i,this.lastSplitLength=n+1):(s.push(i),this.lastSplitLength=s.length),s}getValue(t,e,r,s){return e===t.length?"":0===s?t.substring(e,r):2===s?t.substring(e+1,r-1):t.substring(e+1,r-1).replace(/""/gi,'"')}}class u{}function c(){return new u}const h=[404,408,425,429,500,502,503,504];function f(t){return h.includes(t)}class
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("url"),e=require("http"),r=require("https"),s=require("buffer");function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=n(require("zlib"));function o(){const t=new TextDecoder("utf-8");return{concat(t,e){const r=new Uint8Array(t.length+e.length);return r.set(t),r.set(e,t.length),r},copy(t,e,r){const s=new Uint8Array(r-e);return s.set(t.subarray(e,r)),s},toUtf8String:(e,r,s)=>t.decode(e.subarray(r,s))}}function l(t,e){const r=null!=e?e:o();let s,n=!1,i=!1;return{next(e){if(!n)try{!function(e){let o,l=0;for(s?(e=r.concat(s,e),o=s.length):o=0;o<e.length;){const s=e[o];if(10===s){if(!i){const s=o>0&&13===e[o-1]?o-1:o;if(n)return;t.next(r.toUtf8String(e,l,s)),l=o+1}}else 34===s&&(i=!i);o++}s=l<o?r.copy(e,l,o):void 0}(e)}catch(t){this.error(t)}},error(e){n||(n=!0,t.error(e))},complete(){n||(s&&t.next(r.toUtf8String(s,0,s.length)),n=!0,t.complete())},useCancellable(e){if(t.useCancellable){const r=this;t.useCancellable({cancel(){e.cancel(),s=void 0,r.complete()},isCancelled:()=>e.isCancelled()})}}}}class a{constructor(){this._reuse=!1}get reuse(){return this._reuse}set reuse(t){t&&!this.reusedValues&&(this.reusedValues=new Array(10)),this._reuse=t}withReuse(){return this.reuse=!0,this}splitLine(t){if(null==t)return this.lastSplitLength=0,[];let e=0,r=0;const s=this._reuse?this.reusedValues:[];let n=0;for(let i=0;i<t.length;i++){const o=t[i];if(","===o){if(e%2==0){const o=this.getValue(t,r,i,e);this._reuse?s[n++]=o:s.push(o),r=i+1,e=0}}else'"'===o&&e++}const i=this.getValue(t,r,t.length,e);return this._reuse?(s[n]=i,this.lastSplitLength=n+1):(s.push(i),this.lastSplitLength=s.length),s}getValue(t,e,r,s){return e===t.length?"":0===s?t.substring(e,r):2===s?t.substring(e+1,r-1):t.substring(e+1,r-1).replace(/""/gi,'"')}}class u{}function c(){return new u}const h=[404,408,425,429,500,502,503,504];function f(t){return h.includes(t)}class d extends Error{constructor(t){super(t),this.name="IllegalArgumentError",Object.setPrototypeOf(this,d.prototype)}}class p extends Error{constructor(t,e,r,s,n,i){if(super(),this.statusCode=t,this.statusMessage=e,this.body=r,this.contentType=n,Object.setPrototypeOf(this,p.prototype),i)this.message=i;else if(r){if(null==n?void 0:n.startsWith("application/json"))try{this.json=JSON.parse(r),this.message=this.json.message,this.code=this.json.code}catch(t){}this.message||(this.message=`${t} ${e} : ${r}`)}else this.message=`${t} ${e}`;this.name="HttpError",this.setRetryAfter(s)}setRetryAfter(t){"string"==typeof t&&/^[0-9]+$/.test(t)?this._retryAfter=parseInt(t):this._retryAfter=0}canRetry(){return f(this.statusCode)}retryAfter(){return this._retryAfter}}const g=["ECONNRESET","ENOTFOUND","ESOCKETTIMEDOUT","ETIMEDOUT","ECONNREFUSED","EHOSTUNREACH","EPIPE"];function m(t,e){if(t){let r;return"function"==typeof t.retryAfter?t.retryAfter():(r=0,e&&e>0?r+Math.round(Math.random()*e):r)}return 0}class y extends Error{constructor(){super(),Object.setPrototypeOf(this,y.prototype),this.name="RequestTimedOutError",this.message="Request timed out"}canRetry(){return!0}retryAfter(){return 0}}class x extends Error{constructor(){super(),this.name="AbortError",Object.setPrototypeOf(this,x.prototype),this.message="Response aborted"}canRetry(){return!0}retryAfter(){return 0}}const w=t=>t,b={boolean:t=>"true"===t,unsignedLong:t=>""===t?null:+t,long:t=>""===t?null:+t,double(t){switch(t){case"":return null;case"+Inf":return Number.POSITIVE_INFINITY;case"-Inf":return Number.NEGATIVE_INFINITY;default:return+t}},string:w,base64Binary:w,duration:t=>""===t?null:t,"dateTime:RFC3339":t=>""===t?null:t};class v{constructor(t){t.forEach((t,e)=>t.index=e),this.columns=t}column(t){for(let e=0;e<this.columns.length;e++){const r=this.columns[e];if(r.label===t)return r}throw new d(`Column ${t} not found!`)}toObject(t){var e;const r={};for(let s=0;s<this.columns.length&&s<t.length;s++){let n=t[s];const i=this.columns[s];""===n&&i.defaultValue&&(n=i.defaultValue),r[i.label]=(null!==(e=b[i.dataType])&&void 0!==e?e:w)(n)}return r}}function T(t){return new v(t)}function S(t){const e=(new a).withReuse();let r,s,n=!0,i=0;return{error(e){t.error(e)},next(o){if(""===o)n=!0,r=void 0;else{const l=e.splitLine(o),a=e.lastSplitLength;if(n){if(!r){r=new Array(a);for(let t=0;t<a;t++)r[t]=c()}if(l[0].startsWith("#")){if("#datatype"===l[0])for(let t=1;t<a;t++)r[t].dataType=l[t];else if("#default"===l[0])for(let t=1;t<a;t++)r[t].defaultValue=l[t];else if("#group"===l[0])for(let t=1;t<a;t++)r[t].group="t"===l[t][0]}else{""===l[0]?(i=1,r=r.slice(1)):i=0;for(let t=i;t<a;t++)r[t-i].label=l[t];s=T(r),n=!1}}else t.next(l.slice(i,a),s)}},complete(){t.complete()},useCancellable(e){t.useCancellable&&t.useCancellable(e)}}}const O={timeout:1e4},R={retryJitter:200,minRetryDelay:5e3,maxRetryDelay:125e3,exponentialBase:5,randomRetry:!0},E={batchSize:1e3,flushInterval:6e4,writeFailed:function(){},writeSuccess:function(){},maxRetries:5,maxRetryTime:18e4,maxBufferLines:32e3,retryJitter:200,minRetryDelay:5e3,maxRetryDelay:125e3,exponentialBase:2,gzipThreshold:1e3,randomRetry:!0};function D(t,e){return function(r){let s="",n=0,i=0;for(;i<r.length;){const o=t.indexOf(r[i]);o>=0&&(s+=r.substring(n,i),s+=e[o],n=i+1),i++}return 0==n?r:(n<r.length&&(s+=r.substring(n,r.length)),s)}}const C={measurement:D(", \n\r\t",["\\,","\\ ","\\n","\\r","\\t"]),quoted:function(t,e){const r=D(t,e);return t=>'"'+r(t)+'"'}('"\\',['\\"',"\\\\"]),tag:D(", =\n\r\t",["\\,","\\ ","\\=","\\n","\\r","\\t"])};let A=!1;function $(t){return A=t&&process&&"function"==typeof process.hrtime}$(!0);let j=void 0,_=void 0,P=Date.now(),B=0;function L(){if(A){const t=process.hrtime();let e=Date.now();_?(t[0]=t[0]-_[0],t[1]=t[1]-_[1],t[1]<0&&(t[0]-=1,t[1]+=1e9),e=j+1e3*t[0]+Math.floor(t[1]/1e6)):(_=t,j=e);const r=String(t[1]%1e6);return String(e)+"000000000".substr(0,6-r.length)+r}{const t=Date.now();t!==P?(P=t,B=0):B++;const e=String(B);return String(t)+"000000000".substr(0,6-e.length)+e}}function F(){if(A){const t=process.hrtime(),e=String(Math.trunc(t[1]/1e3)%1e3);return String(Date.now())+"000000000".substr(0,3-e.length)+e}return String(Date.now())+"000000000".substr(0,3)}function M(){return String(Date.now())}function q(){return String(Math.floor(Date.now()/1e3))}const I={s:q,ms:M,us:F,ns:L,seconds:q,millis:M,micros:F,nanos:L},N={s:t=>""+Math.floor(t.getTime()/1e3),ms:t=>""+t.getTime(),us:t=>t.getTime()+"000",ns:t=>t.getTime()+"000000"};function z(t){return void 0===t?L():"string"==typeof t?t.length>0?t:void 0:t instanceof Date?t.getTime()+"000000":String("number"==typeof t?Math.floor(t):t)}const U={error(t,e){console.error("ERROR: "+t,e||"")},warn(t,e){console.warn("WARN: "+t,e||"")}};let k=U;const H={error(t,e){k.error(t,e)},warn(t,e){k.warn(t,e)}};const V=Symbol("FLUX_VALUE");class W{constructor(t){this.fluxValue=t}toString(){return this.fluxValue}[V](){return this.fluxValue}}function J(t){if(null==t)return"";t=t.toString();let e=void 0,r=0;function s(){void 0===e&&(e=t.substring(0,r))}for(;r<t.length;r++){const n=t.charAt(r);switch(n){case"\r":s(),e+="\\r";break;case"\n":s(),e+="\\n";break;case"\t":s(),e+="\\t";break;case'"':case"\\":s(),e=e+"\\"+n;break;case"$":if(r+1<t.length&&"{"===t.charAt(r+1)){s(),r++,e+="\\${";break}null!=e&&(e+=n);break;default:null!=e&&(e+=n)}}return void 0!==e?e:t}function Y(t){if("number"==typeof t){if(!isFinite(t))throw new Error("not a flux float: "+t);return t.toString()}const e=String(t);let r=!1;for(const t of e)if("."!==t){if("."!==t&&"-"!==t&&(t<"0"||t>"9"))throw new Error("not a flux float: "+e)}else{if(r)throw new Error("not a flux float: "+e);r=!r}return e}function G(t){return`regexp.compile(v: "${J(t)}")`}function X(t){return new W(String(t))}function Z(t){if(void 0===t)return"";if(null===t)return"null";if("boolean"==typeof t)return t.toString();if("string"==typeof t)return`"${J(t)}"`;if("number"==typeof t)return Y(t);if("object"==typeof t){if("function"==typeof t[V])return t[V]();if(t instanceof Date)return t.toISOString();if(t instanceof RegExp)return G(t);if(Array.isArray(t))return`[${t.map(Z).join(",")}]`}return Z(t.toString())}const K="function"==typeof Symbol&&Symbol.observable||"@@observable";
|
|
2
2
|
/*! *****************************************************************************
|
|
3
3
|
Copyright (c) Microsoft Corporation.
|
|
4
4
|
|
|
@@ -13,5 +13,5 @@ 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
15
|
***************************************************************************** */
|
|
16
|
-
function Q(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 tt{constructor(t){this.options=Object.assign(Object.assign({},R),t),this.success()}nextDelay(t,e){const r=m(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 et{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);H.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 Q(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 rt{constructor(t,e,r){this.maxChunkRecords=t,this.flushFn=e,this.scheduleSend=r,this.length=0,this.lines=new Array(t)}add(t){0===this.length&&this.scheduleSend(),this.lines[this.length]=t,this.length++,this.length>=this.maxChunkRecords&&this.flush().catch(t=>{})}flush(){const t=this.reset();return t.length>0?this.flushFn(t):Promise.resolve()}reset(){const t=this.lines.slice(0,this.length);return this.length=0,t}}class st{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}`,this.writeOptions=Object.assign(Object.assign({},E),n),this.currentTime=I[s],this.dateToProtocolTimestamp=N[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 rt(this.writeOptions.batchSize,t=>(this._clearFlushTimeout(),this.sendBatch(t,this.writeOptions.maxRetries+1)),()=>{this.writeOptions.flushInterval>0&&(this._clearFlushTimeout(),this.closed||(this._timeoutHandle=setTimeout(()=>this.sendBatch(this.writeBuffer.reset(),this.writeOptions.maxRetries+1).catch(t=>{}),this.writeOptions.flushInterval)))}),this.sendBatch=this.sendBatch.bind(this),this.retryStrategy=(i=this.writeOptions,new tt(i)),this.retryBuffer=new et(this.writeOptions.maxBufferLines,this.sendBatch)}sendBatch(t,e,r=Date.now()+this.writeOptions.maxRetryTime){const s=this,n=s.writeOptions.maxRetries+2-e;if(!this.closed&&t.length>0){if(r<=Date.now()){const t=new Error("Max retry time exceeded.");return H.error(`Write to InfluxDB failed (attempt: ${n}).`,t),Promise.reject(t)}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);if(a)a.then(i,o);else{if(!s.closed&&e>1&&(!(l instanceof d)||l.statusCode>=429))return H.warn(`Write to InfluxDB failed (attempt: ${n}).`,l),s.retryBuffer.addLines(t,e-1,s.retryStrategy.nextDelay(l,n),r),void o(l);H.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 d(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 Q(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&&H.error(`Retry buffer closed with ${t} items that were not written to InfluxDB!`,null),this.closed=!0})}dispose(){return this._clearFlushTimeout(),this.closed=!0,this.retryBuffer.close()+this.writeBuffer.length}useDefaultTags(t){return this.defaultTags=void 0,Object.keys(t).forEach(e=>{(this.defaultTags||(this.defaultTags={}))[e]=C.tag(t[e])}),this}convertTime(t){return void 0===t?this.currentTime():"string"==typeof t?t.length>0?t:void 0:t instanceof Date?this.dateToProtocolTimestamp(t):String("number"==typeof t?Math.floor(t):t)}}const nt={concat:(t,e)=>s.Buffer.concat([t,e]),toUtf8String:(t,e,r)=>t.toString("utf-8",e,r),copy(t,e,r){const n=s.Buffer.allocUnsafe(r-e);return t.copy(n,0,e,r),n}};const it={flush:i.default.constants.Z_SYNC_FLUSH,finishFlush:i.default.constants.Z_SYNC_FLUSH},ot=s.Buffer.allocUnsafe(0);class lt{constructor(){this.cancelled=!1}cancel(){this.cancelled=!0}isCancelled(){return this.cancelled}}class at{constructor(s){var n,i,o,l,a,u,c;this.connectionOptions=s,this.chunkCombiner=nt;const h=t.parse(s.url);if(this.defaultOptions=Object.assign(Object.assign(Object.assign(Object.assign({},O),s),s.transportOptions),{port:h.port,protocol:h.protocol,hostname:h.hostname}),this.contextPath=null!==(n=h.path)&&void 0!==n?n:"",this.contextPath.endsWith("/")&&(this.contextPath=this.contextPath.substring(0,this.contextPath.length-1)),"/api/v2"==this.contextPath&&(H.warn(`Please remove '/api/v2' context path from InfluxDB base url, using ${h.protocol}//${h.hostname}:${h.port} !`),this.contextPath=""),"http:"===h.protocol)this.requestApi=null!==(l=null===(o=null===(i=this.defaultOptions["follow-redirects"])||void 0===i?void 0:i.http)||void 0===o?void 0:o.request)&&void 0!==l?l:e.request;else{if("https:"!==h.protocol)throw new Error(`Unsupported protocol "${h.protocol} in URL: "${s.url}"`);this.requestApi=null!==(c=null===(u=null===(a=this.defaultOptions["follow-redirects"])||void 0===a?void 0:a.https)||void 0===u?void 0:u.request)&&void 0!==c?c:r.request}}send(t,e,r,s){const n=new lt;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=ot;return new Promise((l,a)=>{this.send(t,e,r,{responseStarted(t,e){n&&n(t,e),i=String(t["content-type"])},next:t=>{o=s.Buffer.concat([o,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{s.includes("json")?l(JSON.parse(o.toString("utf8"))):s.includes("text")||s.startsWith("application/csv")?l(o.toString("utf8")):l(o)}catch(t){a(t)}},error:t=>{a(t)}})})}createRequestMessage(t,e,r){const n=s.Buffer.from(e,"utf-8"),o={"content-type":"application/json; charset=utf-8","User-Agent":"influxdb-client-js/1.18.0"};this.connectionOptions.token&&(o.authorization="Token "+this.connectionOptions.token);let l=Promise.resolve(n);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<n.length&&(l=l.then(t=>new Promise((e,r)=>{i.default.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 n=this.requestApi(t,t=>{var r;if(e.isCancelled())return t.resume(),void s.complete();t.on("aborted",()=>{s.error(new x)}),s.responseStarted(t.headers,t.statusCode);const n=null!==(r=t.statusCode)&&void 0!==r?r:600;let o;if("gzip"===t.headers["content-encoding"]?(o=i.default.createGunzip(it),t.pipe(o)):o=t,o.on("error",s.error),n>=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 d(n,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 n.setTimeout&&n.setTimeout(t.timeout),n.on("timeout",()=>{s.error(new y)}),n.on("error",t=>{s.error(t)}),n.on("close",s.complete),t.body&&n.write(t.body),n.end()}}function ut(t,e){return e.toObject(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 ht(){}class ft{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):ht,error:r?r.bind(t):ht,complete:s?s.bind(t):ht}}("object"!=typeof t||null===t?{next:t,error:e,complete:r}:t);return new ct(this.decorator(s),this.executor)}[K](){return this}}const pt={header:!0,delimiter:",",quoteChar:'"',commentPrefix:"#",annotations:["datatype","group","default"]},dt=t=>t;class gt{constructor(t,e){this.transport=t,this.options="string"==typeof e?{org:e}:e}with(t){return new gt(this.transport,Object.assign(Object.assign({},this.options),t))}lines(t){return new ft(this.createExecutor(t),dt)}rows(t){return new ft(this.createExecutor(t),t=>S({next(e,r){t.next({values:e,tableMeta:r})},error(e){t.error(e)},complete(){t.complete()}}))}queryLines(t,e){this.createExecutor(t)(e)}queryRows(t,e){this.createExecutor(t)(S(e))}collectRows(t,e=ut){const r=[];return new Promise((s,n)=>{this.queryRows(t,{next(t,s){const n=e.call(this,t,s);void 0!==n&&r.push(n)},error(t){n(t)},complete(){s(r)}})})}collectLines(t){const e=[];return new Promise((r,s)=>{this.queryLines(t,{next(t){e.push(t)},error(t){s(t)},complete(){r(e)}})})}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:pt,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:pt,type:r})),{method:"POST",headers:Object.assign({"content-type":"application/json; encoding=utf-8","accept-encoding":s?"gzip":"identity"},n)},l(i,this.transport.chunkCombiner))}}decorateRequest(t){var e;return"function"==typeof this.options.now&&(t.now=this.options.now()),t.type=null!==(e=this.options.type)&&void 0!==e?e:"flux",t}}exports.AbortError=x,exports.DEFAULT_ConnectionOptions=O,exports.DEFAULT_RetryDelayStrategyOptions=R,exports.DEFAULT_WriteOptions=E,exports.FLUX_VALUE=V,exports.HttpError=d,exports.IllegalArgumentError=p,exports.InfluxDB=class{constructor(t){var e;if("string"==typeof t)this._options={url:t};else{if(null===t||"object"!=typeof t)throw new p("No url or configuration specified!");this._options=t}const r=this._options.url;if("string"!=typeof r)throw new p("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 at(this._options)}getWriteApi(t,e,r="ns",s){return new st(this.transport,t,e,r,null!=s?s:this._options.writeOptions)}getQueryApi(t){return new gt(this.transport,t)}},exports.LineSplitter=a,exports.Logger=H,exports.Point=class{constructor(t){this.tags={},this.fields={},t&&(this.name=t)}measurement(t){return this.name=t,this}tag(t,e){return this.tags[t]=e,this}booleanField(t,e){return this.fields[t]=e?"T":"F",this}intField(t,e){if("number"!=typeof e){let r;if(isNaN(r=parseInt(String(e))))throw new Error(`Expected integer value for field ${t}, but got '${e}'!`);e=r}return this.fields[t]=Math.floor(e)+"i",this}uintField(t,e){if("number"==typeof e){if(e<0||e>Number.MAX_SAFE_INTEGER)throw new Error("uint value out of js unsigned integer range: "+e);this.fields[t]=Math.floor(e)+"u"}else{const r=String(e);for(let t=0;t<r.length;t++){const s=r.charCodeAt(t);if(s<48||s>57)throw new Error(`uint value has an unsupported character at pos ${t}: ${e}`)}if(r.length>20||20===r.length&&r.localeCompare("18446744073709551615")>0)throw new Error("uint value out of range: "+r);this.fields[t]=r+"u"}return this}floatField(t,e){if("number"!=typeof e){let r;if(isNaN(r=parseFloat(e)))throw new Error(`Expected float value for field ${t}, but got '${e}'!`);e=r}return this.fields[t]=String(e),this}stringField(t,e){return null!=e&&("string"!=typeof e&&(e=String(e)),this.fields[t]=C.quoted(e)),this}timestamp(t){return this.time=t,this}toLineProtocol(t){if(!this.name)return;let e="";if(Object.keys(this.fields).sort().forEach(t=>{if(t){const r=this.fields[t];e.length>0&&(e+=","),e+=`${C.tag(t)}=${r}`}}),0===e.length)return;let r="";const s=t&&t.defaultTags?Object.assign(Object.assign({},t.defaultTags),this.tags):this.tags;Object.keys(s).sort().forEach(t=>{if(t){const e=s[t];e&&(r+=",",r+=`${C.tag(t)}=${C.tag(e)}`)}});let n=this.time;return n=t&&t.convertTime?t.convertTime(n):z(n),`${C.measurement(this.name)}${r} ${e}${void 0!==n?" "+n:""}`}toString(){const t=this.toLineProtocol(void 0);return t||"invalid point: "+JSON.stringify(this,void 0)}},exports.RequestTimedOutError=y,exports.canRetryHttpCall=function(t){return!!t&&("function"==typeof t.canRetry?!!t.canRetry():!(!t.code||!g.includes(t.code)))},exports.chunksToLines=l,exports.consoleLogger=U,exports.convertTimeToNanos=z,exports.createFluxTableColumn=function(t){var e,r;const s=new u;return s.label=String(t.label),s.dataType=t.dataType,s.group=Boolean(t.group),s.defaultValue=null!==(e=t.defaultValue)&&void 0!==e?e:"",s.index=null!==(r=t.index)&&void 0!==r?r:0,s},exports.createFluxTableMetaData=T,exports.createTextDecoderCombiner=o,exports.currentTime=I,exports.dateToProtocolTimestamp=N,exports.escape=C,exports.flux=function(t,...e){if(1==t.length&&0===e.length)return X(t[0]);const r=new Array(t.length+e.length);let s=0;for(let i=0;i<t.length;i++){const o=t[i];if(r[s++]=o,i<e.length){const l=e[i];let a;if(o.endsWith('"')&&i+1<t.length&&t[i+1].startsWith('"'))a=J(l);else if(a=Z(l),""===a&&("object"!=typeof(n=l)||"function"!=typeof n[V]))throw new Error(`Unsupported parameter literal '${l}' at index: ${i}, type: ${typeof l}`);r[s++]=a}else if(i<t.length-1)throw new Error("Too few parameters supplied!")}var n;return X(r.join(""))},exports.fluxBool=function(t){return new W("true"===t||"false"===t?t:(!!t).toString())},exports.fluxDateTime=function(t){return new W(function(t){return`time(v: "${J(t)}")`}(t))},exports.fluxDuration=function(t){return new W(`duration(v: "${J(t)}")`)},exports.fluxExpression=X,exports.fluxFloat=function(t){return new W(Y(t))},exports.fluxInteger=function(t){const e=Y(t);for(const t of e)if("."===t)throw new Error("not a flux integer: "+e);return new W(e)},exports.fluxRegExp=function(t){return new W(G(t))},exports.fluxString=function(t){return new W(`"${J(t)}"`)},exports.getRetryDelay=m,exports.isStatusCodeRetriable=f,exports.linesToTables=S,exports.newFluxTableColumn=c,exports.sanitizeFloat=Y,exports.serializeDateTimeAsDate=function(){b["dateTime:RFC3339"]=t=>""===t?null:new Date(Date.parse(t))},exports.serializeDateTimeAsNumber=function(){b["dateTime:RFC3339"]=t=>""===t?null:Date.parse(t)},exports.serializeDateTimeAsString=function(){b["dateTime:RFC3339"]=t=>""===t?null:t},exports.setLogger=function(t){const e=k;return k=t,e},exports.stringToLines=function(t,e){let r=!1,s=0,n=0;for(;n<t.length;){const i=t.charCodeAt(n);if(10===i){if(!r){const r=n>0&&13===t.charCodeAt(n-1)?n-1:n;e.next(t.substring(s,r)),s=n+1}}else 34===i&&(r=!r);n++}s<n&&e.next(t.substring(s,n)),e.complete()},exports.symbolObservable=K,exports.toFluxValue=Z,exports.typeSerializers=b,exports.useProcessHrtime=j;
|
|
16
|
+
function Q(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 tt{constructor(t){this.options=Object.assign(Object.assign({},R),t),this.success()}nextDelay(t,e){const r=m(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 et{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);H.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 Q(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 rt{constructor(t,e,r){this.maxChunkRecords=t,this.flushFn=e,this.scheduleSend=r,this.length=0,this.lines=new Array(t)}add(t){0===this.length&&this.scheduleSend(),this.lines[this.length]=t,this.length++,this.length>=this.maxChunkRecords&&this.flush().catch(t=>{})}flush(){const t=this.reset();return t.length>0?this.flushFn(t):Promise.resolve()}reset(){const t=this.lines.slice(0,this.length);return this.length=0,t}}class st{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}`,this.writeOptions=Object.assign(Object.assign({},E),n),this.currentTime=I[s],this.dateToProtocolTimestamp=N[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 rt(this.writeOptions.batchSize,t=>(this._clearFlushTimeout(),this.sendBatch(t,this.writeOptions.maxRetries+1)),()=>{this.writeOptions.flushInterval>0&&(this._clearFlushTimeout(),this.closed||(this._timeoutHandle=setTimeout(()=>this.sendBatch(this.writeBuffer.reset(),this.writeOptions.maxRetries+1).catch(t=>{}),this.writeOptions.flushInterval)))}),this.sendBatch=this.sendBatch.bind(this),this.retryStrategy=(i=this.writeOptions,new tt(i)),this.retryBuffer=new et(this.writeOptions.maxBufferLines,this.sendBatch)}sendBatch(t,e,r=Date.now()+this.writeOptions.maxRetryTime){const s=this,n=s.writeOptions.maxRetries+2-e;if(!this.closed&&t.length>0){if(r<=Date.now()){const t=new Error("Max retry time exceeded.");return H.error(`Write to InfluxDB failed (attempt: ${n}).`,t),Promise.reject(t)}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);if(a)a.then(i,o);else{if(!s.closed&&e>1&&(!(l instanceof p)||l.statusCode>=429))return H.warn(`Write to InfluxDB failed (attempt: ${n}).`,l),s.retryBuffer.addLines(t,e-1,s.retryStrategy.nextDelay(l,n),r),void o(l);H.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 p(l,t,void 0,"0");e.message=t,a.error(e)}}};this.transport.send(this.httpPath,t.join("\n"),this.sendOptions,a)})}return Promise.resolve()}_clearFlushTimeout(){void 0!==this._timeoutHandle&&(clearTimeout(this._timeoutHandle),this._timeoutHandle=void 0)}writeRecord(t){if(this.closed)throw new Error("writeApi: already closed!");this.writeBuffer.add(t)}writeRecords(t){if(this.closed)throw new Error("writeApi: already closed!");for(let e=0;e<t.length;e++)this.writeBuffer.add(t[e])}writePoint(t){if(this.closed)throw new Error("writeApi: already closed!");const e=t.toLineProtocol(this);e&&this.writeBuffer.add(e)}writePoints(t){if(this.closed)throw new Error("writeApi: already closed!");for(let e=0;e<t.length;e++){const r=t[e].toLineProtocol(this);r&&this.writeBuffer.add(r)}}flush(t){return Q(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&&H.error(`Retry buffer closed with ${t} items that were not written to InfluxDB!`,null),this.closed=!0})}dispose(){return this._clearFlushTimeout(),this.closed=!0,this.retryBuffer.close()+this.writeBuffer.length}useDefaultTags(t){return this.defaultTags=void 0,Object.keys(t).forEach(e=>{(this.defaultTags||(this.defaultTags={}))[e]=C.tag(t[e])}),this}convertTime(t){return void 0===t?this.currentTime():"string"==typeof t?t.length>0?t:void 0:t instanceof Date?this.dateToProtocolTimestamp(t):String("number"==typeof t?Math.floor(t):t)}}const nt={concat:(t,e)=>s.Buffer.concat([t,e]),toUtf8String:(t,e,r)=>t.toString("utf-8",e,r),copy(t,e,r){const n=s.Buffer.allocUnsafe(r-e);return t.copy(n,0,e,r),n}};const it={flush:i.default.constants.Z_SYNC_FLUSH,finishFlush:i.default.constants.Z_SYNC_FLUSH},ot=s.Buffer.allocUnsafe(0);class lt{constructor(){this.cancelled=!1}cancel(){this.cancelled=!0}isCancelled(){return this.cancelled}}class at{constructor(s){var n,i,o,l,a,u,c;this.connectionOptions=s,this.chunkCombiner=nt;const h=t.parse(s.url);if(this.defaultOptions=Object.assign(Object.assign(Object.assign(Object.assign({},O),s),s.transportOptions),{port:h.port,protocol:h.protocol,hostname:h.hostname}),this.contextPath=null!==(n=h.path)&&void 0!==n?n:"",this.contextPath.endsWith("/")&&(this.contextPath=this.contextPath.substring(0,this.contextPath.length-1)),"/api/v2"==this.contextPath&&(H.warn(`Please remove '/api/v2' context path from InfluxDB base url, using ${h.protocol}//${h.hostname}:${h.port} !`),this.contextPath=""),"http:"===h.protocol)this.requestApi=null!==(l=null===(o=null===(i=this.defaultOptions["follow-redirects"])||void 0===i?void 0:i.http)||void 0===o?void 0:o.request)&&void 0!==l?l:e.request;else{if("https:"!==h.protocol)throw new Error(`Unsupported protocol "${h.protocol} in URL: "${s.url}"`);this.requestApi=null!==(c=null===(u=null===(a=this.defaultOptions["follow-redirects"])||void 0===a?void 0:a.https)||void 0===u?void 0:u.request)&&void 0!==c?c:r.request}}send(t,e,r,s){const n=new lt;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=ot;return new Promise((l,a)=>{this.send(t,e,r,{responseStarted(t,e){n&&n(t,e),i=String(t["content-type"])},next:t=>{o=s.Buffer.concat([o,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{s.includes("json")?l(JSON.parse(o.toString("utf8"))):s.includes("text")||s.startsWith("application/csv")?l(o.toString("utf8")):l(o)}catch(t){a(t)}},error:t=>{a(t)}})})}createRequestMessage(t,e,r){const n=s.Buffer.from(e,"utf-8"),o={"content-type":"application/json; charset=utf-8","User-Agent":"influxdb-client-js/1.19.0"};this.connectionOptions.token&&(o.authorization="Token "+this.connectionOptions.token);let l=Promise.resolve(n);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<n.length&&(l=l.then(t=>new Promise((e,r)=>{i.default.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 n=this.requestApi(t,t=>{var r;if(e.isCancelled())return t.resume(),void s.complete();t.on("aborted",()=>{s.error(new x)}),s.responseStarted(t.headers,t.statusCode);const n=null!==(r=t.statusCode)&&void 0!==r?r:600;let o;if("gzip"===t.headers["content-encoding"]?(o=i.default.createGunzip(it),t.pipe(o)):o=t,o.on("error",s.error),n>=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 p(n,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 n.setTimeout&&n.setTimeout(t.timeout),n.on("timeout",()=>{s.error(new y)}),n.on("error",t=>{s.error(t)}),n.on("close",s.complete),t.body&&n.write(t.body),n.end()}}function ut(t,e){return e.toObject(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 ht(){}class ft{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):ht,error:r?r.bind(t):ht,complete:s?s.bind(t):ht}}("object"!=typeof t||null===t?{next:t,error:e,complete:r}:t);return new ct(this.decorator(s),this.executor)}[K](){return this}}const dt={header:!0,delimiter:",",quoteChar:'"',commentPrefix:"#",annotations:["datatype","group","default"]},pt=t=>t;class gt{constructor(t,e){this.transport=t,this.options="string"==typeof e?{org:e}:e}with(t){return new gt(this.transport,Object.assign(Object.assign({},this.options),t))}lines(t){return new ft(this.createExecutor(t),pt)}rows(t){return new ft(this.createExecutor(t),t=>S({next(e,r){t.next({values:e,tableMeta:r})},error(e){t.error(e)},complete(){t.complete()}}))}queryLines(t,e){this.createExecutor(t)(e)}queryRows(t,e){this.createExecutor(t)(S(e))}collectRows(t,e=ut){const r=[];return new Promise((s,n)=>{this.queryRows(t,{next(t,s){const n=e.call(this,t,s);void 0!==n&&r.push(n)},error(t){n(t)},complete(){s(r)}})})}collectLines(t){const e=[];return new Promise((r,s)=>{this.queryLines(t,{next(t){e.push(t)},error(t){s(t)},complete(){r(e)}})})}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:dt,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:dt,type:r})),{method:"POST",headers:Object.assign({"content-type":"application/json; encoding=utf-8","accept-encoding":s?"gzip":"identity"},n)},l(i,this.transport.chunkCombiner))}}decorateRequest(t){var e;return"function"==typeof this.options.now&&(t.now=this.options.now()),t.type=null!==(e=this.options.type)&&void 0!==e?e:"flux",t}}exports.AbortError=x,exports.DEFAULT_ConnectionOptions=O,exports.DEFAULT_RetryDelayStrategyOptions=R,exports.DEFAULT_WriteOptions=E,exports.FLUX_VALUE=V,exports.HttpError=p,exports.IllegalArgumentError=d,exports.InfluxDB=class{constructor(t){var e;if("string"==typeof t)this._options={url:t};else{if(null===t||"object"!=typeof t)throw new d("No url or configuration specified!");this._options=t}const r=this._options.url;if("string"!=typeof r)throw new d("No url specified!");r.endsWith("/")&&(this._options.url=r.substring(0,r.length-1)),this.transport=null!==(e=this._options.transport)&&void 0!==e?e:new at(this._options)}getWriteApi(t,e,r="ns",s){return new st(this.transport,t,e,r,null!=s?s:this._options.writeOptions)}getQueryApi(t){return new gt(this.transport,t)}},exports.LineSplitter=a,exports.Logger=H,exports.Point=class{constructor(t){this.tags={},this.fields={},t&&(this.name=t)}measurement(t){return this.name=t,this}tag(t,e){return this.tags[t]=e,this}booleanField(t,e){return this.fields[t]=e?"T":"F",this}intField(t,e){let r;if(r="number"==typeof e?e:parseInt(String(e)),isNaN(r)||r<=-0x8000000000000000||r>=0x8000000000000000)throw new Error(`invalid integer value for field '${t}': '${e}'!`);return this.fields[t]=Math.floor(r)+"i",this}uintField(t,e){if("number"==typeof e){if(isNaN(e)||e<0||e>Number.MAX_SAFE_INTEGER)throw new Error(`uint value for field '${t}' out of range: ${e}`);this.fields[t]=Math.floor(e)+"u"}else{const r=String(e);for(let t=0;t<r.length;t++){const s=r.charCodeAt(t);if(s<48||s>57)throw new Error(`uint value has an unsupported character at pos ${t}: ${e}`)}if(r.length>20||20===r.length&&r.localeCompare("18446744073709551615")>0)throw new Error(`uint value for field '${t}' out of range: ${r}`);this.fields[t]=r+"u"}return this}floatField(t,e){let r;if(r="number"==typeof e?e:parseFloat(e),!isFinite(r))throw new Error(`invalid float value for field '${t}': ${e}`);return this.fields[t]=String(r),this}stringField(t,e){return null!=e&&("string"!=typeof e&&(e=String(e)),this.fields[t]=C.quoted(e)),this}timestamp(t){return this.time=t,this}toLineProtocol(t){if(!this.name)return;let e="";if(Object.keys(this.fields).sort().forEach(t=>{if(t){const r=this.fields[t];e.length>0&&(e+=","),e+=`${C.tag(t)}=${r}`}}),0===e.length)return;let r="";const s=t&&t.defaultTags?Object.assign(Object.assign({},t.defaultTags),this.tags):this.tags;Object.keys(s).sort().forEach(t=>{if(t){const e=s[t];e&&(r+=",",r+=`${C.tag(t)}=${C.tag(e)}`)}});let n=this.time;return n=t&&t.convertTime?t.convertTime(n):z(n),`${C.measurement(this.name)}${r} ${e}${void 0!==n?" "+n:""}`}toString(){const t=this.toLineProtocol(void 0);return t||"invalid point: "+JSON.stringify(this,void 0)}},exports.RequestTimedOutError=y,exports.canRetryHttpCall=function(t){return!!t&&("function"==typeof t.canRetry?!!t.canRetry():!(!t.code||!g.includes(t.code)))},exports.chunksToLines=l,exports.consoleLogger=U,exports.convertTimeToNanos=z,exports.createFluxTableColumn=function(t){var e,r;const s=new u;return s.label=String(t.label),s.dataType=t.dataType,s.group=Boolean(t.group),s.defaultValue=null!==(e=t.defaultValue)&&void 0!==e?e:"",s.index=null!==(r=t.index)&&void 0!==r?r:0,s},exports.createFluxTableMetaData=T,exports.createTextDecoderCombiner=o,exports.currentTime=I,exports.dateToProtocolTimestamp=N,exports.escape=C,exports.flux=function(t,...e){if(1==t.length&&0===e.length)return X(t[0]);const r=new Array(t.length+e.length);let s=0;for(let i=0;i<t.length;i++){const o=t[i];if(r[s++]=o,i<e.length){const l=e[i];let a;if(o.endsWith('"')&&i+1<t.length&&t[i+1].startsWith('"'))a=J(l);else if(a=Z(l),""===a&&("object"!=typeof(n=l)||"function"!=typeof n[V]))throw new Error(`Unsupported parameter literal '${l}' at index: ${i}, type: ${typeof l}`);r[s++]=a}else if(i<t.length-1)throw new Error("Too few parameters supplied!")}var n;return X(r.join(""))},exports.fluxBool=function(t){return new W("true"===t||"false"===t?t:(!!t).toString())},exports.fluxDateTime=function(t){return new W(function(t){return`time(v: "${J(t)}")`}(t))},exports.fluxDuration=function(t){return new W(`duration(v: "${J(t)}")`)},exports.fluxExpression=X,exports.fluxFloat=function(t){return new W(Y(t))},exports.fluxInteger=function(t){const e=Y(t);for(const t of e)if("."===t)throw new Error("not a flux integer: "+e);return new W(e)},exports.fluxRegExp=function(t){return new W(G(t))},exports.fluxString=function(t){return new W(`"${J(t)}"`)},exports.getRetryDelay=m,exports.isStatusCodeRetriable=f,exports.linesToTables=S,exports.newFluxTableColumn=c,exports.sanitizeFloat=Y,exports.serializeDateTimeAsDate=function(){b["dateTime:RFC3339"]=t=>""===t?null:new Date(Date.parse(t))},exports.serializeDateTimeAsNumber=function(){b["dateTime:RFC3339"]=t=>""===t?null:Date.parse(t)},exports.serializeDateTimeAsString=function(){b["dateTime:RFC3339"]=t=>""===t?null:t},exports.setLogger=function(t){const e=k;return k=t,e},exports.stringToLines=function(t,e){let r=!1,s=0,n=0;for(;n<t.length;){const i=t.charCodeAt(n);if(10===i){if(!r){const r=n>0&&13===t.charCodeAt(n-1)?n-1:n;e.next(t.substring(s,r)),s=n+1}}else 34===i&&(r=!r);n++}s<n&&e.next(t.substring(s,n)),e.complete()},exports.symbolObservable=K,exports.toFluxValue=Z,exports.typeSerializers=b,exports.useProcessHrtime=$;
|
|
17
17
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.gz
CHANGED
|
Binary file
|