influx-point-formatter
Version:
InfluxDB Point Formatter
82 lines (81 loc) • 2.24 kB
TypeScript
import * as grammar from './grammar';
import { ISchemaOptions } from './schema';
export { INanoDate, FieldType, Precision, Raw, TimePrecision, escape, toNanoDate } from './grammar';
export { ISchemaOptions } from './schema';
export interface IPointFormatterOptions {
/**
* A list of schema for measurements in the database.
*/
schema?: ISchemaOptions[];
}
export interface IFormatOptions {
/**
* Precision at which the points are written, defaults to nanoseconds 'n'.
*/
precision?: grammar.TimePrecision;
}
export interface IPoint {
/**
* Measurement is the Influx measurement name.
*/
measurement: string;
/**
* Tags is the list of tag values to insert.
*/
tags?: {
[name: string]: string;
};
/**
* Fields is the list of field values to insert.
*/
fields?: {
[name: string]: any;
};
/**
* Timestamp tags this measurement with a date. This can be a Date object,
* in which case we'll adjust it to the desired precision, or a numeric
* string or number, in which case it gets passed directly to Influx.
*/
timestamp?: Date | string | number;
}
export declare class PointFormatter {
/**
* Config options for Influx.
* @private
*/
private _options;
/**
* Map of Schema instances defining measurements in Influx.
* @private
*/
private _schema;
/**
* Creates a formatter with the default options.
*/
constructor();
/**
* Creates a formatter with custom options.
*/
constructor(options: IPointFormatterOptions);
/**
* Adds specified schema for better fields coercing.
*
* @param {ISchemaOptions} schema
* @memberof PointFormatter
*/
addSchema(schema: ISchemaOptions): void;
/**
* Formats a point in the InfluxDB line protocol format.
* @param point
* @param options
*/
formatPoint(point: IPoint, options?: IFormatOptions): string;
/**
* Creates specified measurement schema
*
* @private
* @param {ISchemaOptions} schema
* @memberof PointFormatter
*/
private _createSchema;
}