influx 5.0.3 → 5.0.7

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.
@@ -1,119 +1,118 @@
1
- /// <reference types="node" />
2
- import { TimePrecision } from './grammar';
3
- /**
4
- * A ResultError is thrown when a query generates errorful results from Influx.
5
- */
6
- export declare class ResultError extends Error {
7
- constructor(message: string);
8
- }
9
- /**
10
- * InfluxResults describes the result structure received from InfluxDB.
11
- *
12
- * NOTE: if you're poking around in Influx, use curl, not the `json` formatter
13
- * provided by the CLI. As of 1.0 this formatter changes the result structure
14
- * and it will confuse you, as it did me ;)
15
- */
16
- export interface IResponse {
17
- results: IResultEntry[];
18
- }
19
- export interface IResultEntry {
20
- series?: IResponseSeries[];
21
- error?: string;
22
- }
23
- export declare type Tags = {
24
- [name: string]: string;
25
- };
26
- export declare type Row = any;
27
- export interface IResponseSeries {
28
- name?: string;
29
- columns: string[];
30
- tags?: Tags;
31
- values?: Row[];
32
- }
33
- /**
34
- * IResultsParser is a user-friendly results tables from raw Influx responses.
35
- */
36
- export interface IResults<T> extends Array<T> {
37
- /**
38
- * Group looks for and returns the first group in the results
39
- * that matches the provided tags.
40
- *
41
- * If you've used lodash or underscore, we do something quite similar to
42
- * their object matching: for every row in the results, if it contains tag
43
- * values matching the requested object, we return it.
44
- *
45
- * @param {Object.<String, String>} matcher
46
- * @return {T[]}
47
- * @example
48
- * // Matching tags sets in queries:
49
- * influx.query('select * from perf group by host').then(results => {
50
- * expect(results.group({ host: 'ares.peet.io'})).to.deep.equal([
51
- * { host: 'ares.peet.io', cpu: 0.12, mem: 2435 },
52
- * { host: 'ares.peet.io', cpu: 0.10, mem: 2451 },
53
- * // ...
54
- * ])
55
- *
56
- * expect(results.group({ host: 'box1.example.com'})).to.deep.equal([
57
- * { host: 'box1.example.com', cpu: 0.54, mem: 8420 },
58
- * // ...
59
- * ])
60
- * })
61
- */
62
- group(matcher: Tags): T[];
63
- /**
64
- * Returns the data grouped into nested arrays, similarly to how it was
65
- * returned from Influx originally.
66
- *
67
- * @returns {Array<{ name: String, tags: Object.<String, String>, rows: T[] }>
68
- * @example
69
- * influx.query('select * from perf group by host').then(results => {
70
- * expect(results.groups()).to.deep.equal([
71
- * {
72
- * name: 'perf',
73
- * tags: { host: 'ares.peet.io' },
74
- * rows: [
75
- * { host: 'ares.peet.io', cpu: 0.12, mem: 2435 },
76
- * { host: 'ares.peet.io', cpu: 0.10, mem: 2451 },
77
- * // ...
78
- * ]
79
- * }
80
- * {
81
- * name: 'perf',
82
- * tags: { host: 'box1.example.com' },
83
- * rows: [
84
- * { host: 'box1.example.com', cpu: 0.54, mem: 8420 },
85
- * // ...
86
- * ]
87
- * }
88
- * ])
89
- * })
90
- */
91
- groups(): {
92
- name: string;
93
- tags: Tags;
94
- rows: T[];
95
- }[];
96
- }
97
- /**
98
- * Checks if there are any errors in the IResponse and, if so, it throws them.
99
- * @private
100
- * @throws {ResultError}
101
- */
102
- export declare function assertNoErrors(res: IResponse): IResponse;
103
- /**
104
- * From parses out a response to a result or list of responses.
105
- * There are three situations we cover here:
106
- * 1. A single query without groups, like `select * from myseries`
107
- * 2. A single query with groups, generated with a `group by` statement
108
- * which groups by series *tags*, grouping by times is case (1)
109
- * 3. Multiple queries of types 1 and 2
110
- * @private
111
- */
112
- export declare function parse<T>(res: IResponse, precision?: TimePrecision): IResults<T>[] | IResults<T>;
113
- /**
114
- * parseSingle asserts that the response contains a single result,
115
- * and returns that result.
116
- * @throws {Error} if the number of results is not exactly one
117
- * @private
118
- */
119
- export declare function parseSingle<T>(res: IResponse, precision?: TimePrecision): IResults<T>;
1
+ import { TimePrecision } from './grammar';
2
+ /**
3
+ * A ResultError is thrown when a query generates errorful results from Influx.
4
+ */
5
+ export declare class ResultError extends Error {
6
+ constructor(message: string);
7
+ }
8
+ /**
9
+ * InfluxResults describes the result structure received from InfluxDB.
10
+ *
11
+ * NOTE: if you're poking around in Influx, use curl, not the `json` formatter
12
+ * provided by the CLI. As of 1.0 this formatter changes the result structure
13
+ * and it will confuse you, as it did me ;)
14
+ */
15
+ export interface IResponse {
16
+ results: IResultEntry[];
17
+ }
18
+ export interface IResultEntry {
19
+ series?: IResponseSeries[];
20
+ error?: string;
21
+ }
22
+ export declare type Tags = {
23
+ [name: string]: string;
24
+ };
25
+ export declare type Row = any;
26
+ export interface IResponseSeries {
27
+ name?: string;
28
+ columns: string[];
29
+ tags?: Tags;
30
+ values?: Row[];
31
+ }
32
+ /**
33
+ * IResultsParser is a user-friendly results tables from raw Influx responses.
34
+ */
35
+ export interface IResults<T> extends Array<T> {
36
+ /**
37
+ * Group looks for and returns the first group in the results
38
+ * that matches the provided tags.
39
+ *
40
+ * If you've used lodash or underscore, we do something quite similar to
41
+ * their object matching: for every row in the results, if it contains tag
42
+ * values matching the requested object, we return it.
43
+ *
44
+ * @param {Object.<String, String>} matcher
45
+ * @return {T[]}
46
+ * @example
47
+ * // Matching tags sets in queries:
48
+ * influx.query('select * from perf group by host').then(results => {
49
+ * expect(results.group({ host: 'ares.peet.io'})).to.deep.equal([
50
+ * { host: 'ares.peet.io', cpu: 0.12, mem: 2435 },
51
+ * { host: 'ares.peet.io', cpu: 0.10, mem: 2451 },
52
+ * // ...
53
+ * ])
54
+ *
55
+ * expect(results.group({ host: 'box1.example.com'})).to.deep.equal([
56
+ * { host: 'box1.example.com', cpu: 0.54, mem: 8420 },
57
+ * // ...
58
+ * ])
59
+ * })
60
+ */
61
+ group(matcher: Tags): T[];
62
+ /**
63
+ * Returns the data grouped into nested arrays, similarly to how it was
64
+ * returned from Influx originally.
65
+ *
66
+ * @returns {Array<{ name: String, tags: Object.<String, String>, rows: T[] }>
67
+ * @example
68
+ * influx.query('select * from perf group by host').then(results => {
69
+ * expect(results.groups()).to.deep.equal([
70
+ * {
71
+ * name: 'perf',
72
+ * tags: { host: 'ares.peet.io' },
73
+ * rows: [
74
+ * { host: 'ares.peet.io', cpu: 0.12, mem: 2435 },
75
+ * { host: 'ares.peet.io', cpu: 0.10, mem: 2451 },
76
+ * // ...
77
+ * ]
78
+ * }
79
+ * {
80
+ * name: 'perf',
81
+ * tags: { host: 'box1.example.com' },
82
+ * rows: [
83
+ * { host: 'box1.example.com', cpu: 0.54, mem: 8420 },
84
+ * // ...
85
+ * ]
86
+ * }
87
+ * ])
88
+ * })
89
+ */
90
+ groups(): {
91
+ name: string;
92
+ tags: Tags;
93
+ rows: T[];
94
+ }[];
95
+ }
96
+ /**
97
+ * Checks if there are any errors in the IResponse and, if so, it throws them.
98
+ * @private
99
+ * @throws {ResultError}
100
+ */
101
+ export declare function assertNoErrors(res: IResponse): IResponse;
102
+ /**
103
+ * From parses out a response to a result or list of responses.
104
+ * There are three situations we cover here:
105
+ * 1. A single query without groups, like `select * from myseries`
106
+ * 2. A single query with groups, generated with a `group by` statement
107
+ * which groups by series *tags*, grouping by times is case (1)
108
+ * 3. Multiple queries of types 1 and 2
109
+ * @private
110
+ */
111
+ export declare function parse<T>(res: IResponse, precision?: TimePrecision): IResults<T>[] | IResults<T>;
112
+ /**
113
+ * parseSingle asserts that the response contains a single result,
114
+ * and returns that result.
115
+ * @throws {Error} if the number of results is not exactly one
116
+ * @private
117
+ */
118
+ export declare function parseSingle<T>(res: IResponse, precision?: TimePrecision): IResults<T>;
@@ -1,139 +1,146 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || function (d, b) {
3
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
4
- function __() { this.constructor = d; }
5
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
6
- };
7
- var grammar_1 = require('./grammar');
8
- /**
9
- * A ResultError is thrown when a query generates errorful results from Influx.
10
- */
11
- var ResultError = (function (_super) {
12
- __extends(ResultError, _super);
13
- function ResultError(message) {
14
- _super.call(this);
15
- this.message = "Error from InfluxDB: " + message;
16
- }
17
- return ResultError;
18
- }(Error));
19
- exports.ResultError = ResultError;
20
- function groupMethod(matcher) {
21
- // We do a tiny bit of 'custom' deep equality checking here, taking
22
- // advantage of the fact that the tag keys are consistent across all
23
- // series results. This lets us match groupings much more efficiently,
24
- // ~6000x faster than the fastest vanilla equality checker (lodash)
25
- // when operating on large (~100,000 grouping) sets.
26
- var srcKeys = this.groupsTagsKeys;
27
- var dstKeys = Object.keys(matcher);
28
- if (srcKeys.length === 0 || srcKeys.length !== dstKeys.length) {
29
- return [];
30
- }
31
- L: for (var i = 0; i < this.groupRows.length; i += 1) {
32
- for (var k = 0; k < srcKeys.length; k += 1) {
33
- if (this.groupRows[i].tags[srcKeys[k]] !== matcher[srcKeys[k]]) {
34
- continue L;
35
- }
36
- }
37
- return this.groupRows[i].rows;
38
- }
39
- return [];
40
- }
41
- function groupsMethod() {
42
- return this.groupRows;
43
- }
44
- /**
45
- * Inner parsing function which unpacks the series into a table and attaches
46
- * methods to the array. This is quite optimized and a bit of a mess to read,
47
- * but it's all fairly easy procedural logic.
48
- *
49
- * We do this instead of subclassing Array since subclassing has some
50
- * undesirable side-effects. For example, calling .slice() on the array
51
- * makes it impossible to preserve groups as would be necessary if it's
52
- * subclassed.
53
- */
54
- function parseInner(series, precision) {
55
- if (series === void 0) { series = []; }
56
- var results = [];
57
- var tags = results.groupsTagsKeys
58
- = series.length && series[0].tags ? Object.keys(series[0].tags) : [];
59
- var nextGroup = [];
60
- results.groupRows = new Array(series.length); // tslint:disable-line
61
- var lastEnd = 0;
62
- for (var i = 0; i < series.length; i += 1, lastEnd = results.length) {
63
- var _a = series[i], _b = _a.columns, columns = _b === void 0 ? [] : _b, _c = _a.values, values = _c === void 0 ? [] : _c;
64
- for (var k = 0; k < values.length; k += 1) {
65
- var obj = {};
66
- for (var j = 0; j < columns.length; j += 1) {
67
- if (columns[j] === 'time') {
68
- obj.time = grammar_1.isoOrTimeToDate(values[k][j], precision);
69
- }
70
- else {
71
- obj[columns[j]] = values[k][j];
72
- }
73
- }
74
- for (var j = 0; j < tags.length; j += 1) {
75
- obj[tags[j]] = series[i].tags[tags[j]];
76
- }
77
- results.push(obj);
78
- nextGroup.push(obj);
79
- }
80
- results.groupRows[i] = {
81
- name: series[i].name,
82
- rows: nextGroup,
83
- tags: series[i].tags || {},
84
- };
85
- nextGroup = [];
86
- }
87
- results.group = groupMethod;
88
- results.groups = groupsMethod;
89
- return results;
90
- }
91
- /**
92
- * Checks if there are any errors in the IResponse and, if so, it throws them.
93
- * @private
94
- * @throws {ResultError}
95
- */
96
- function assertNoErrors(res) {
97
- for (var i = 0; i < res.results.length; i += 1) {
98
- var error = res.results[i].error;
99
- if (error) {
100
- throw new ResultError(error);
101
- }
102
- }
103
- return res;
104
- }
105
- exports.assertNoErrors = assertNoErrors;
106
- /**
107
- * From parses out a response to a result or list of responses.
108
- * There are three situations we cover here:
109
- * 1. A single query without groups, like `select * from myseries`
110
- * 2. A single query with groups, generated with a `group by` statement
111
- * which groups by series *tags*, grouping by times is case (1)
112
- * 3. Multiple queries of types 1 and 2
113
- * @private
114
- */
115
- function parse(res, precision) {
116
- assertNoErrors(res);
117
- if (res.results.length === 1) {
118
- return parseInner(res.results[0].series, precision);
119
- }
120
- else {
121
- return res.results.map(function (result) { return parseInner(result.series, precision); });
122
- }
123
- }
124
- exports.parse = parse;
125
- /**
126
- * parseSingle asserts that the response contains a single result,
127
- * and returns that result.
128
- * @throws {Error} if the number of results is not exactly one
129
- * @private
130
- */
131
- function parseSingle(res, precision) {
132
- assertNoErrors(res);
133
- if (res.results.length !== 1) {
134
- throw new Error('node-influx expected the results length to equal 1, but ' +
135
- ("it was " + 0 + ". Please report this here: https://git.io/influx-err"));
136
- }
137
- return parseInner(res.results[0].series, precision);
138
- }
139
- exports.parseSingle = parseSingle;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6
+ return function (d, b) {
7
+ extendStatics(d, b);
8
+ function __() { this.constructor = d; }
9
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
10
+ };
11
+ })();
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ var grammar_1 = require("./grammar");
14
+ /**
15
+ * A ResultError is thrown when a query generates errorful results from Influx.
16
+ */
17
+ var ResultError = (function (_super) {
18
+ __extends(ResultError, _super);
19
+ function ResultError(message) {
20
+ var _this = _super.call(this) || this;
21
+ _this.message = "Error from InfluxDB: " + message;
22
+ return _this;
23
+ }
24
+ return ResultError;
25
+ }(Error));
26
+ exports.ResultError = ResultError;
27
+ function groupMethod(matcher) {
28
+ // We do a tiny bit of 'custom' deep equality checking here, taking
29
+ // advantage of the fact that the tag keys are consistent across all
30
+ // series results. This lets us match groupings much more efficiently,
31
+ // ~6000x faster than the fastest vanilla equality checker (lodash)
32
+ // when operating on large (~100,000 grouping) sets.
33
+ var srcKeys = this.groupsTagsKeys;
34
+ var dstKeys = Object.keys(matcher);
35
+ if (srcKeys.length === 0 || srcKeys.length !== dstKeys.length) {
36
+ return [];
37
+ }
38
+ L: for (var i = 0; i < this.groupRows.length; i += 1) {
39
+ for (var k = 0; k < srcKeys.length; k += 1) {
40
+ if (this.groupRows[i].tags[srcKeys[k]] !== matcher[srcKeys[k]]) {
41
+ continue L;
42
+ }
43
+ }
44
+ return this.groupRows[i].rows;
45
+ }
46
+ return [];
47
+ }
48
+ function groupsMethod() {
49
+ return this.groupRows;
50
+ }
51
+ /**
52
+ * Inner parsing function which unpacks the series into a table and attaches
53
+ * methods to the array. This is quite optimized and a bit of a mess to read,
54
+ * but it's all fairly easy procedural logic.
55
+ *
56
+ * We do this instead of subclassing Array since subclassing has some
57
+ * undesirable side-effects. For example, calling .slice() on the array
58
+ * makes it impossible to preserve groups as would be necessary if it's
59
+ * subclassed.
60
+ */
61
+ function parseInner(series, precision) {
62
+ if (series === void 0) { series = []; }
63
+ var results = [];
64
+ var tags = results.groupsTagsKeys
65
+ = series.length && series[0].tags ? Object.keys(series[0].tags) : [];
66
+ var nextGroup = [];
67
+ results.groupRows = new Array(series.length); // tslint:disable-line
68
+ var lastEnd = 0;
69
+ for (var i = 0; i < series.length; i += 1, lastEnd = results.length) {
70
+ var _a = series[i], _b = _a.columns, columns = _b === void 0 ? [] : _b, _c = _a.values, values = _c === void 0 ? [] : _c;
71
+ for (var k = 0; k < values.length; k += 1) {
72
+ var obj = {};
73
+ for (var j = 0; j < columns.length; j += 1) {
74
+ if (columns[j] === 'time') {
75
+ obj.time = grammar_1.isoOrTimeToDate(values[k][j], precision);
76
+ }
77
+ else {
78
+ obj[columns[j]] = values[k][j];
79
+ }
80
+ }
81
+ for (var j = 0; j < tags.length; j += 1) {
82
+ obj[tags[j]] = series[i].tags[tags[j]];
83
+ }
84
+ results.push(obj);
85
+ nextGroup.push(obj);
86
+ }
87
+ results.groupRows[i] = {
88
+ name: series[i].name,
89
+ rows: nextGroup,
90
+ tags: series[i].tags || {},
91
+ };
92
+ nextGroup = [];
93
+ }
94
+ results.group = groupMethod;
95
+ results.groups = groupsMethod;
96
+ return results;
97
+ }
98
+ /**
99
+ * Checks if there are any errors in the IResponse and, if so, it throws them.
100
+ * @private
101
+ * @throws {ResultError}
102
+ */
103
+ function assertNoErrors(res) {
104
+ for (var i = 0; i < res.results.length; i += 1) {
105
+ var error = res.results[i].error;
106
+ if (error) {
107
+ throw new ResultError(error);
108
+ }
109
+ }
110
+ return res;
111
+ }
112
+ exports.assertNoErrors = assertNoErrors;
113
+ /**
114
+ * From parses out a response to a result or list of responses.
115
+ * There are three situations we cover here:
116
+ * 1. A single query without groups, like `select * from myseries`
117
+ * 2. A single query with groups, generated with a `group by` statement
118
+ * which groups by series *tags*, grouping by times is case (1)
119
+ * 3. Multiple queries of types 1 and 2
120
+ * @private
121
+ */
122
+ function parse(res, precision) {
123
+ assertNoErrors(res);
124
+ if (res.results.length === 1) {
125
+ return parseInner(res.results[0].series, precision);
126
+ }
127
+ else {
128
+ return res.results.map(function (result) { return parseInner(result.series, precision); });
129
+ }
130
+ }
131
+ exports.parse = parse;
132
+ /**
133
+ * parseSingle asserts that the response contains a single result,
134
+ * and returns that result.
135
+ * @throws {Error} if the number of results is not exactly one
136
+ * @private
137
+ */
138
+ function parseSingle(res, precision) {
139
+ assertNoErrors(res);
140
+ if (res.results.length !== 1) {
141
+ throw new Error('node-influx expected the results length to equal 1, but ' +
142
+ ("it was " + 0 + ". Please report this here: https://git.io/influx-err"));
143
+ }
144
+ return parseInner(res.results[0].series, precision);
145
+ }
146
+ exports.parseSingle = parseSingle;