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,QAAI,KAAK,UAAU;AAClB,WAAK,SAAS,YAAY,OAAO,IAAI,CAAC,UAAU,KAAK,OAAO,KAAK,CAAC,CAAC;AACnE,aAAO;AAAA,IACR;AAEA,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAa,MAAM,iBAA2B;AAC7C,QAAI,KAAK,UAAU;AAClB,YAAM,KAAK,SAAS,MAAM,eAAe;AACzC,aAAO;AAAA,IACR;AAEA,WAAO;AAAA,EACR;AAAA,EAEQ,OAAO,OAAc;AAC5B,eAAW,CAAC,MAAM,KAAK,KAAK,KAAK,cAAc;AAC9C,YAAM,IAAI,MAAM,KAAK;AAAA,IACtB;AAEA,WAAO;AAAA,EACR;AACD;AA1FoB;AAAb,IAAM,SAAN","sourcesContent":["import { type ClientOptions, InfluxDB, Point, type QueryApi, type WriteApi, type WritePrecisionType } from '@influxdata/influxdb-client';\nimport { tryNumberParse } from '../utils';\n\nexport class Client {\n\tpublic readonly influx: InfluxDB;\n\tpublic readonly queryApi?: QueryApi;\n\tpublic readonly writeApi?: WriteApi;\n\tpublic messageCount = 0;\n\n\tprivate readonly injectedTags: [name: string, value: string][] = [];\n\n\tpublic constructor(options: Client.Options);\n\tpublic constructor({ org, writeBucket, writePrecision, ...options }: Client.Options = {}) {\n\t\tthis.influx = new InfluxDB(\n\t\t\tprocess.env.INFLUX_OPTIONS_STRING ?? {\n\t\t\t\t...options,\n\t\t\t\turl: options.url ?? process.env.INFLUX_URL!,\n\t\t\t\tproxyUrl: options.proxyUrl ?? process.env.INFLUX_PROXY_URL,\n\t\t\t\ttimeout: options.timeout ?? tryNumberParse(process.env.INFLUX_TIMEOUT),\n\t\t\t\ttoken: options.token ?? process.env.INFLUX_TOKEN\n\t\t\t}\n\t\t);\n\n\t\tconst _org = org ?? process.env.INFLUX_ORG;\n\t\tif (_org) {\n\t\t\tthis.queryApi = this.influx.getQueryApi(_org);\n\n\t\t\tconst _bucket = writeBucket ?? process.env.INFLUX_WRITE_BUCKET;\n\t\t\tif (_bucket) {\n\t\t\t\tconst _precision = writePrecision ?? (process.env.INFLUX_WRITE_PRECISION as WritePrecisionType | undefined);\n\t\t\t\tthis.writeApi = this.influx.getWriteApi(_org, _bucket, _precision);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Adds a tag that will be injected in all points.\n\t * @param name The name of the tag to inject.\n\t * @param value The value of the tag to inject.\n\t */\n\tpublic addInjectTag(name: string, value: string) {\n\t\tthis.injectedTags.push([name, value]);\n\t}\n\n\t/**\n\t * Writes a point into the write buffer.\n\t * @param point The point to write.\n\t * @returns Whether or not the point was successfully written.\n\t */\n\tpublic writePoint(point: Point) {\n\t\tif (this.writeApi) {\n\t\t\tthis.writeApi.writePoint(this.inject(point));\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * Writes multiple points into the write buffer.\n\t * @param points The points to write.\n\t * @returns Whether or not the points were successfully written.\n\t */\n\tpublic writePoints(points: readonly Point[]) {\n\t\tif (this.writeApi) {\n\t\t\tthis.writeApi.writePoints(points.map((point) => this.inject(point)));\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * Flushes the pending writes to the server.\n\t * @param withRetryBuffer Whether or not it should flush the scheduled retries\n\t * @returns Whether or not the operation was successful.\n\t */\n\tpublic async flush(withRetryBuffer?: boolean) {\n\t\tif (this.writeApi) {\n\t\t\tawait this.writeApi.flush(withRetryBuffer);\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tprivate inject(point: Point) {\n\t\tfor (const [name, value] of this.injectedTags) {\n\t\t\tpoint.tag(name, value);\n\t\t}\n\n\t\treturn point;\n\t}\n}\n\nexport namespace Client {\n\texport interface Options extends Partial<ClientOptions> {\n\t\torg?: string;\n\t\twriteBucket?: string;\n\t\twritePrecision?: WritePrecisionType;\n\t}\n}\n"]}