6 lines
28 KiB
JavaScript
6 lines
28 KiB
JavaScript
|
"use strict";var influxdb=(()=>{var k=Object.defineProperty;var Ae=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var Ee=Object.prototype.hasOwnProperty;var Pe=(r,e)=>{for(var t in e)k(r,t,{get:e[t],enumerable:!0})},Fe=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of De(e))!Ee.call(r,i)&&i!==t&&k(r,i,{get:()=>e[i],enumerable:!(n=Ae(e,i))||n.enumerable});return r};var Le=r=>Fe(k({},"__esModule",{value:!0}),r);var nt={};Pe(nt,{AbortError:()=>x,DEFAULT_ConnectionOptions:()=>We,DEFAULT_RetryDelayStrategyOptions:()=>Y,DEFAULT_WriteOptions:()=>Z,FLUX_VALUE:()=>D,HttpError:()=>m,IllegalArgumentError:()=>y,InfluxDB:()=>U,LineSplitter:()=>b,Log:()=>p,Point:()=>ue,RequestTimedOutError:()=>v,UNKNOWN_COLUMN:()=>Q,canRetryHttpCall:()=>Be,chunksToLines:()=>R,chunksToLinesIterable:()=>M,consoleLogger:()=>Te,convertTimeToNanos:()=>se,createFluxTableColumn:()=>Ie,createFluxTableMetaData:()=>A,createTextDecoderCombiner:()=>g,currentTime:()=>ne,dateToProtocolTimestamp:()=>ie,escape:()=>w,flux:()=>et,fluxBool:()=>Ze,fluxDateTime:()=>Ge,fluxDuration:()=>Ke,fluxExpression:()=>oe,fluxFloat:()=>qe,fluxInteger:()=>Je,fluxRegExp:()=>Ye,fluxString:()=>je,getRetryDelay:()=>j,isStatusCodeRetriable:()=>pe,linesToRowsIterable:()=>J,linesToTables:()=>V,newFluxTableColumn:()=>S,sanitizeFloat:()=>ae,sanitizeInteger:()=>le,serializeDateTimeAsDate:()=>Me,serializeDateTimeAsNumber:()=>_e,serializeDateTimeAsString:()=>Ve,setLogger:()=>Ne,stringToLines:()=>ze,symbolObservable:()=>X,toFluxValue:()=>H,typeSerializers:()=>C,useProcessHrtime:()=>we});function g(){let r=new TextDecoder("utf-8");return{concat(e,t){let n=new Uint8Array(e.length+t.length);return n.set(e),n.set(t,e.length),n},copy(e,t,n){let i=new Uint8Array(n-t);return i.set(e.subarray(t,n)),i},toUtf8String(e,t,n){return r.decode(e.subarray(t,n))}}}function R(r,e){let t=e!=null?e:g(),n,i=!1,s=!1,o=!1,a;function f(l){let c,d=0;for(n?(c=l.length===0?0:n.length,l=t.concat(n,l)):c=0;c<l.length;){let T=l[c];if(T===10){if(!s){let $=c>0&&l[c-1]===13?c-1:c;if(i)return;if(o=r.next(t.toUtf8String(l,d,$))===!1,d=c+1,o)break}}else T===34&&(s=!s);c++}if(d<l.length?n=t.copy(l,d,l.length):n=void 0,o){if(r.useResume){r.useResume(()=>{o=!1,f(new Uint8Array(0))});return}u.error(new Error("Unable to pause, useResume is not configured!")),o=!1}a&&(a(),a=void 0)}let u={next(l){if(!i)try{return f(l),!o}catch(c){this.error(c)}return!0},error(l){i||(i=!0,r.error(l))},complete(){i||(n&&r.next(t.toUtf8String(n,0,n.length)),i=!0,r.complete())}};return r.useCancellable&&(u.useCancellable=l=>{r.useCancellable&&r.useCancellable({cancel(){l.cancel(),n=void 0,u.complete()},isCancelled(){return l.isCancelled()}})}),r.useResume&&(u.useResume=l=>{a=l}),u}async function*M(r,e){let t=e!=null?e:g(),n,i=!1;for await(let s of r){let o,a=0;for(n?(o=n.length,s=t.concat(n,s)):o=0;o<s.length;){let f=s[o];if(f===10){if(!i){let u=o>0&&s[o-1]===13?o-1:o;yield t.toUtf8String(s,a,u),a=o+1}}else f===34&&(i=!i);o++}a<s.length?n=t.copy(s,a,s.length):n=void 0}n&&(yield t.toUtf8String(n,0,n.length))}var b=class{constructor(){this._reuse=!1}get reuse(){return this._reuse}set reuse(e){e&&!this.reusedValues&&(this.reusedValues=new Array(10)),this._reuse=e}withReuse(){return this.reuse=!0,this}splitLine(e){if(e==null)return this.lastSplitLength=0,[];let t=0,n=0,i=this._reuse?this.reusedValues:[],s=0;for(let a=0;a<e.length;a++){let f=e[a];if(f===","){if(t%2===0){let u=this.getValue(e,n,a,t);this._reuse?i[s++]=u:i.push(u),n=a+1,t=0}}else f==='"'&&t++}let o=this.getValue(e,n,e.length,t);return this._reuse?(i[s]=o,this.lastSplitLength=s+1):(i.push(o),this.lastSplitLength=i.length),i}getValue(e,t,n,i){return t===e.length?"":i===0?e.substring(t,n):i===2?e.substring(t+1,n-1):e.substring(t+1,n-1).replace(/""/gi,'"')}};var N=r=>r,C={boolean:r=>r===""?null:r==="true",unsignedLong:r=>r===""?null:+r,long:r=>r===""?null:+r,double(r){switch(r){case"":return null;case"+Inf":return Number.POSITIVE_INFINITY;case"-Inf":return Number.NEGATIVE_INFINITY;default:return+r}},string:N,base64Binary:N,duration:r=>r===""?null:r,"dateTime:RFC3
|
||
|
\r `,["\\,","\\ ","\\n","\\r","\\t"]),quoted:ke('"\\',['\\"',"\\\\"]),tag:ee(`, =
|
||
|
\r `,["\\,","\\ ","\\=","\\n","\\r","\\t"])};var xe="000000000";function we(r){return!1}we(!0);var he=Date.now(),te=0;function re(){{let r=Date.now();r!==he?(he=r,te=0):te++;let e=String(te);return String(r)+xe.substr(0,6-e.length)+e}}function ye(){return String(Date.now())+xe.substr(0,3)}function ge(){return String(Date.now())}function be(){return String(Math.floor(Date.now()/1e3))}var ne={s:be,ms:ge,us:ye,ns:re,seconds:be,millis:ge,micros:ye,nanos:re},ie={s:r=>`${Math.floor(r.getTime()/1e3)}`,ms:r=>`${r.getTime()}`,us:r=>`${r.getTime()}000`,ns:r=>`${r.getTime()}000000`};function se(r){return r===void 0?re():typeof r=="string"?r.length>0?r:void 0:r instanceof Date?`${r.getTime()}000000`:String(typeof r=="number"?Math.floor(r):r)}var Te={error(r,e){console.error("ERROR: "+r,e||"")},warn(r,e){console.warn("WARN: "+r,e||"")}},z=Te,p={error(r,e){z.error(r,e)},warn(r,e){z.warn(r,e)}};function Ne(r){let e=z;return z=r,e}var D=Symbol("FLUX_VALUE"),h=class{constructor(e){this.fluxValue=e}toString(){return this.fluxValue}[D](){return this.fluxValue}};function Qe(r){return typeof r=="object"&&typeof r[D]=="function"}function E(r){if(r==null)return"";r=r.toString();let e,t=0;function n(){e===void 0&&(e=r.substring(0,t))}for(;t<r.length;t++){let i=r.charAt(t);switch(i){case"\r":n(),e+="\\r";break;case`
|
||
|
`:n(),e+="\\n";break;case" ":n(),e+="\\t";break;case'"':case"\\":n(),e=e+"\\"+i;break;case"$":if(t+1<r.length&&r.charAt(t+1)==="{"){n(),t++,e+="\\${";break}e!=null&&(e+=i);break;default:e!=null&&(e+=i)}}return e!==void 0?e:r}function je(r){return new h(`"${E(r)}"`)}function ae(r){let e=Number(r);if(!isFinite(e)){if(typeof r=="number")return`float(v: "${e}")`;throw new Error(`not a flux float: ${r}`)}let t=e.toString(),n=!1;for(let i of t)if(!(i>="0"&&i<="9"||i=="-")){if(i==="."){n=!0;continue}return`float(v: "${t}")`}return n?t:t+".0"}function qe(r){return new h(ae(r))}function le(r){let e=String(r),t=e.startsWith("-"),n=t?e.substring(1):e;if(n.length===0||n.length>19)throw new Error(`not a flux integer: ${e}`);for(let i of n)if(i<"0"||i>"9")throw new Error(`not a flux integer: ${e}`);if(n.length===19){if(t&&n>"9223372036854775808")throw new Error(`flux integer out of bounds: ${e}`);if(!t&&n>"9223372036854775807")throw new Error(`flux integer out of bounds: ${e}`)}return e}function Je(r){return new h(le(r))}function Xe(r){return`time(v: "${E(r)}")`}function Ge(r){return new h(Xe(r))}function Ke(r){return new h(`duration(v: "${E(r)}")`)}function Re(r){return r instanceof RegExp?r.toString():new RegExp(r).toString()}function Ye(r){return new h(Re(r))}function Ze(r){return r==="true"||r==="false"?new h(r):new h((!!r).toString())}function oe(r){return new h(String(r))}function H(r){if(r===void 0)return"";if(r===null)return"null";if(typeof r=="boolean")return r.toString();if(typeof r=="string")return`"${E(r)}"`;if(typeof r=="number")return Number.isSafeInteger(r)?le(r):ae(r);if(typeof r=="object"){if(typeof r[D]=="function")return r[D]();if(r instanceof Date)return r.toISOString();if(r instanceof RegExp)return Re(r);if(Array.isArray(r))return`[${r.map(H).join(",")}]`}else if(typeof r=="bigint")return`${r}.0`;return H(r.toString())}function et(r,...e){if(r.length==1&&e.length===0)return oe(r[0]);let t=new Array(r.length+e.length),n=0;for(let i=0;i<r.length;i++){let s=r[i];if(t[n++]=s,i<e.length){let o=e[i],a;if(s.endsWith('"')&&i+1<r.length&&r[i+1].startsWith('"'))a=E(o);else if(a=H(o),a===""&&!Qe(o))throw new Error(`Unsupported parameter literal '${o}' at index: ${i}, type: ${typeof o}`);t[n++]=a}else if(i<r.length-1)throw new Error("Too few parameters supplied!")}return oe(t.join(""))}var ue=class{constructor(e){this.tags={};this.fields={};e&&(this.name=e)}measurement(e){return this.name=e,this}tag(e,t){return this.tags[e]=t,this}booleanField(e,t){return this.fields[e]=t?"T":"F",this}intField(e,t){let n;if(typeof t=="number"?n=t:n=parseInt(String(t)),isNaN(n)||n<=-9223372036854776e3||n>=9223372036854776e3)throw new Error(`invalid integer value for field '${e}': '${t}'!`);return this.fields[e]=`${Math.floor(n)}i`,this}uintField(e,t){if(typeof t=="number"){if(isNaN(t)||t<0||t>Number.MAX_SAFE_INTEGER)throw new Error(`uint value for field '${e}' out of range: ${t}`);this.fields[e]=`${Math.floor(t)}u`}else{let n=String(t);for(let i=0;i<n.length;i++){let s=n.charCodeAt(i);if(s<48||s>57)throw new Error(`uint value has an unsupported character at pos ${i}: ${t}`)}if(n.length>20||n.length===20&&n.localeCompare("18446744073709551615")>0)throw new Error(`uint value for field '${e}' out of range: ${n}`);this.fields[e]=`${n}u`}return this}floatField(e,t){let n;if(typeof t=="number"?n=t:n=parseFloat(t),!isFinite(n))throw new Error(`invalid float value for field '${e}': ${t}`);return this.fields[e]=String(n),this}stringField(e,t){return t!=null&&(typeof t!="string"&&(t=String(t)),this.fields[e]=w.quoted(t)),this}timestamp(e){return this.time=e,this}toLineProtocol(e){if(!this.name)return;let t="";if(Object.keys(this.fields).sort().forEach(o=>{if(o){let a=this.fields[o];t.length>0&&(t+=","),t+=`${w.tag(o)}=${a}`}}),t.length===0)return;let n="",i=e&&e.defaultTags?{...e.defaultTags,...this.tags}:this.tags;Object.keys(i).sort().forEach(o=>{if(o){let a=i[o];a&&(n+=",",n+=`${w.tag(o)}=${w.tag(a)}`)}});let s=this.time;return e&&e.convertTime?s=e.convertTime(s):s=se(s),`${w.measurement(this.name)}${n} ${t}${s!==void 0?" "+s:""}`}toString(){let e=t
|
||
|
`),this.sendOptions,u)})}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 t=0;t<e.length;t++)this.writeBuffer.add(e[t])}writePoint(e){if(this.closed)throw new Error("writeApi: already closed!");let t=e.toLineProtocol(this);t&&this.writeBuffer.add(t)}writePoints(e){if(this.closed)throw new Error("writeApi: already closed!");for(let t=0;t<e.length;t++){let n=e[t].toLineProtocol(this);n&&this.writeBuffer.add(n)}}async flush(e){if(await this.writeBuffer.flush(),e)return await this.retryBuffer.flush()}close(){return this.writeBuffer.flush().finally(()=>{let t=this.retryBuffer.close();t&&p.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(e){return this.defaultTags=e,this}convertTime(e){return e===void 0?this.currentTime():typeof e=="string"?e.length>0?e:void 0:e instanceof Date?this.dateToProtocolTimestamp(e):String(typeof e=="number"?Math.floor(e):e)}};function me(r={}){let e=0,t={next:n=>{if(e===0&&r.next&&n!==null&&n!==void 0)return r.next(n)},error:n=>{e===0&&(e=1,r.error&&r.error(n))},complete:()=>{e===0&&(e=2,r.complete&&r.complete())},responseStarted:(n,i)=>{r.responseStarted&&r.responseStarted(n,i)}};return r.useCancellable&&(t.useCancellable=r.useCancellable.bind(r)),r.useResume&&(t.useResume=r.useResume.bind(r)),t}function Oe(r){let e={};return r.headers.forEach((t,n)=>{let i=e[n];i===void 0?e[n]=t:Array.isArray(i)?i.push(t):e[n]=[i,t]}),e}var L=class{constructor(e){this.connectionOptions=e;this.chunkCombiner=g();this.requestDecorator=function(){};this.defaultHeaders={"content-type":"application/json; charset=utf-8",...e.headers},this.connectionOptions.token&&(this.defaultHeaders.Authorization="Token "+this.connectionOptions.token),this.url=String(this.connectionOptions.url),this.url.endsWith("/")&&(this.url=this.url.substring(0,this.url.length-1)),this.url.endsWith("/api/v2")&&(this.url=this.url.substring(0,this.url.length-7),p.warn(`Please remove '/api/v2' context path from InfluxDB base url, using ${this.url} !`))}send(e,t,n,i){let s=me(i),o=!1,a=n.signal,f,u=()=>{},l=u;if(i&&i.useCancellable){let c=new AbortController;a||(a=c.signal,n={...n,signal:a}),a.addEventListener("abort",()=>{l()}),i.useCancellable({cancel(){o=!0,c.abort()},isCancelled(){return o||a.aborted}})}this.fetch(e,t,n).then(async c=>{if(i!=null&&i.responseStarted&&s.responseStarted(Oe(c),c.status),await this.throwOnErrorResponse(c),c.body){let d=c.body.getReader(),T;do{if(f&&await f,o)break;if(T=await d.read(),s.next(T.value)===!1){let $=s.useResume;if(!$){let B="Unable to pause, useResume is not configured!";return await d.cancel(B),Promise.reject(new Error(B))}f=new Promise(B=>{l=()=>{B(),f=void 0,l=u},$(l)})}}while(!T.done)}else if(c.arrayBuffer){let d=await c.arrayBuffer();s.next(new Uint8Array(d))}else{let d=await c.text();s.next(new TextEncoder().encode(d))}}).catch(c=>{o||s.error(c)}).finally(()=>s.complete())}async throwOnErrorResponse(e){if(e.status>=300){let t="";try{if(t=await e.text(),!t){let n=e.headers.get("x-influxdb-error");n&&(t=n)}}catch(n){throw p.warn("Unable to receive error body",n),new m(e.status,e.statusText,void 0,e.headers.get("retry-after"),e.headers.get("content-type"))}throw new m(e.status,e.statusText,t,e.headers.get("retry-after"),e.headers.get("content-type"))}}async*iterate(e,t,n){var s;let i=await this.fetch(e,t,n);if(await this.throwOnErrorResponse(i),i.body){let o=i.body.getReader();for(;;){let{value:a,done:f}=await o.read();if(f)break;if((s=n.signal)!=null&&s.aborted)throw await i.body.cancel(),new x;yield a}}else if(i.arrayBuffer){let o=await i.arrayBuffer();yield new Uint8Array(o)}else{let o=await i.text();yield new TextEncoder().encode(o)}}async request(e,t,n,i){
|
||
|
//# sourceMappingURL=influxdb.js.map
|