Comparing version
@@ -108,2 +108,17 @@ /// <reference types="node" /> | ||
} | ||
export interface IParsedPoint extends IPoint { | ||
/** | ||
* Fields Pairs is the list of key/value pairs for each field on the point | ||
*/ | ||
fieldsPairs: Array<[string, string]>; | ||
/** | ||
* Tags Names is the list of tag names in the point | ||
*/ | ||
tagsNames: string[]; | ||
/** | ||
* Casted Timestamp is the timestamp value after being casted to the | ||
* desired precision. Default 'n' | ||
*/ | ||
castedTimestamp?: string; | ||
} | ||
export interface IWriteOptions { | ||
@@ -147,2 +162,13 @@ /** | ||
} | ||
export interface IParseOptions { | ||
/** | ||
* Precision at which the points are written, defaults to nanoseconds 'n'. | ||
*/ | ||
precision?: grammar.TimePrecision; | ||
/** | ||
* Database under which to write the points. This is required if a default | ||
* database is not provided in Influx. | ||
*/ | ||
database?: string; | ||
} | ||
/** | ||
@@ -680,2 +706,48 @@ * IRetentionOptions are passed into passed into the {@link | ||
/** | ||
* ParsePoint will perform the coercions/schema checks and return the data | ||
* required for writing a point. This will throw an error if a schema check | ||
* or coercion fails. This can be useful for flagging or "throwing out" bad | ||
* points in a batch write to prevent the entire batch from getting aborted | ||
* | ||
* --- | ||
* | ||
* A note when using this function, {@link InfluxDB#writePoints} will still perform | ||
* the same checks, so any pre-processed data will be checked for validity twice which | ||
* has potential performance implications on large data sets | ||
* | ||
* @param point | ||
* @param [options] | ||
* @return | ||
* @example | ||
* // parse a point as if it is getting written to the default | ||
* // databse with the default time precision | ||
* influx.parsePoint({ | ||
* measurement: 'perf', | ||
* tags: { host: 'box1.example.com' }, | ||
* fields: { cpu: getCpuUsage(), mem: getMemUsage() }, | ||
* }) | ||
* | ||
* // you can manually specify the database and time precision | ||
* influx.parsePoint({ | ||
* measurement: 'perf', | ||
* tags: { host: 'box1.example.com' }, | ||
* fields: { cpu: getCpuUsage(), mem: getMemUsage() }, | ||
* }, { | ||
* precision: 's', | ||
* database: 'my_db' | ||
* }) | ||
* | ||
* // if an error occurs, you can catch the error with try...catch | ||
* try { | ||
* influx.parsePoint({ | ||
* measurement: 'perf', | ||
* tags: { host: 'box1.example.com', myExtraneousTag: 'value' }, | ||
* fields: { cpu: getCpuUsage(), mem: getMemUsage(), myExtraneousField: 'value' }, | ||
* }) | ||
* } catch(err) { | ||
* handleError(err); | ||
* } | ||
*/ | ||
parsePoint(point: IPoint, options?: IParseOptions): IParsedPoint; | ||
/** | ||
* WriteMeasurement functions similarly to {@link InfluxDB#writePoints}, but | ||
@@ -682,0 +754,0 @@ * it automatically fills in the `measurement` value for all points for you. |
@@ -834,8 +834,3 @@ "use strict"; | ||
points.forEach((point) => { | ||
const { fields = {}, tags = {}, measurement, timestamp } = point; | ||
const schema = this._schema[database] && this._schema[database][measurement]; | ||
const fieldsPairs = schema | ||
? schema.coerceFields(fields) | ||
: schema_1.coerceBadly(fields); | ||
const tagsNames = schema ? schema.checkTags(tags) : Object.keys(tags); | ||
const { measurement, tags, fieldsPairs, tagsNames, castedTimestamp, } = this.parsePoint(point, { database, precision }); | ||
payload += (payload.length > 0 ? "\n" : "") + measurement; | ||
@@ -856,4 +851,4 @@ for (let tagsName of tagsNames) { | ||
} | ||
if (timestamp !== undefined) { | ||
payload += " " + grammar.castTimestamp(timestamp, precision); | ||
if (castedTimestamp !== undefined) { | ||
payload += " " + castedTimestamp; | ||
} | ||
@@ -875,2 +870,66 @@ }); | ||
/** | ||
* ParsePoint will perform the coercions/schema checks and return the data | ||
* required for writing a point. This will throw an error if a schema check | ||
* or coercion fails. This can be useful for flagging or "throwing out" bad | ||
* points in a batch write to prevent the entire batch from getting aborted | ||
* | ||
* --- | ||
* | ||
* A note when using this function, {@link InfluxDB#writePoints} will still perform | ||
* the same checks, so any pre-processed data will be checked for validity twice which | ||
* has potential performance implications on large data sets | ||
* | ||
* @param point | ||
* @param [options] | ||
* @return | ||
* @example | ||
* // parse a point as if it is getting written to the default | ||
* // databse with the default time precision | ||
* influx.parsePoint({ | ||
* measurement: 'perf', | ||
* tags: { host: 'box1.example.com' }, | ||
* fields: { cpu: getCpuUsage(), mem: getMemUsage() }, | ||
* }) | ||
* | ||
* // you can manually specify the database and time precision | ||
* influx.parsePoint({ | ||
* measurement: 'perf', | ||
* tags: { host: 'box1.example.com' }, | ||
* fields: { cpu: getCpuUsage(), mem: getMemUsage() }, | ||
* }, { | ||
* precision: 's', | ||
* database: 'my_db' | ||
* }) | ||
* | ||
* // if an error occurs, you can catch the error with try...catch | ||
* try { | ||
* influx.parsePoint({ | ||
* measurement: 'perf', | ||
* tags: { host: 'box1.example.com', myExtraneousTag: 'value' }, | ||
* fields: { cpu: getCpuUsage(), mem: getMemUsage(), myExtraneousField: 'value' }, | ||
* }) | ||
* } catch(err) { | ||
* handleError(err); | ||
* } | ||
*/ | ||
parsePoint(point, options = {}) { | ||
const { database = this._defaultDB(), precision = "n" } = options; | ||
const { fields = {}, tags = {}, measurement, timestamp } = point; | ||
const schema = this._schema[database] && this._schema[database][measurement]; | ||
const fieldsPairs = schema | ||
? schema.coerceFields(fields) | ||
: schema_1.coerceBadly(fields); | ||
const tagsNames = schema ? schema.checkTags(tags) : Object.keys(tags); | ||
const castedTimestamp = timestamp && grammar.castTimestamp(timestamp, precision); | ||
return { | ||
fields, | ||
tags, | ||
measurement, | ||
timestamp, | ||
fieldsPairs, | ||
tagsNames, | ||
castedTimestamp, | ||
}; | ||
} | ||
/** | ||
* WriteMeasurement functions similarly to {@link InfluxDB#writePoints}, but | ||
@@ -877,0 +936,0 @@ * it automatically fills in the `measurement` value for all points for you. |
{ | ||
"name": "influx", | ||
"version": "5.7.0", | ||
"version": "5.8.0", | ||
"description": "InfluxDB Client", | ||
@@ -50,3 +50,3 @@ "main": "./lib/src/index.js", | ||
"awesome-typescript-loader": "5.2.1", | ||
"chai": "4.2.0", | ||
"chai": "4.3.3", | ||
"coveralls": "^3.1.0", | ||
@@ -64,3 +64,3 @@ "esdoc": "1.1.0", | ||
"karma-webpack": "^5.0.0-alpha.5", | ||
"lodash": "4.17.20", | ||
"lodash": "4.17.21", | ||
"mocha": "^8.2.1", | ||
@@ -71,3 +71,3 @@ "node-fetch": "2.6.1", | ||
"prettier": "^2.0.5", | ||
"puppeteer": "^5.5.0", | ||
"puppeteer": "^8.0.0", | ||
"semantic-release": "^17.1.1", | ||
@@ -74,0 +74,0 @@ "sinon": "^9.0.2", |
@@ -12,5 +12,5 @@ <p align="center"> | ||
<p align="center"> | ||
<a href="https://travis-ci.org/node-influx/node-influx"> | ||
<img src="https://img.shields.io/travis/node-influx/node-influx/master.svg?style=flat-square" | ||
alt="Travis Build"> | ||
<a href="https://github.com/node-influx/node-influx/actions"> | ||
<img src="https://img.shields.io/github/workflow/status/node-influx/node-influx/CI/master?style=flat-square" | ||
alt="CI Status"> | ||
</a> | ||
@@ -17,0 +17,0 @@ <a href=""> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
157203
3.13%4290
3.15%