influx 5.0.6 → 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.
- package/lib/src/backoff/backoff.d.ts +15 -15
- package/lib/src/backoff/backoff.js +2 -2
- package/lib/src/backoff/exponential.d.ts +52 -52
- package/lib/src/backoff/exponential.js +40 -40
- package/lib/src/builder.d.ts +265 -265
- package/lib/src/builder.js +366 -366
- package/lib/src/doc.d.ts +315 -315
- package/lib/src/doc.js +340 -340
- package/lib/src/grammar/ds.d.ts +45 -45
- package/lib/src/grammar/ds.js +56 -56
- package/lib/src/grammar/escape.d.ts +25 -25
- package/lib/src/grammar/escape.js +108 -108
- package/lib/src/grammar/index.d.ts +3 -3
- package/lib/src/grammar/index.js +8 -8
- package/lib/src/grammar/times.d.ts +74 -74
- package/lib/src/grammar/times.js +325 -325
- package/lib/src/host.d.ts +26 -26
- package/lib/src/host.js +34 -34
- package/lib/src/index.d.ts +659 -659
- package/lib/src/index.js +870 -870
- package/lib/src/pool.d.ts +149 -149
- package/lib/src/pool.js +344 -344
- package/lib/src/results.d.ts +118 -118
- package/lib/src/results.js +146 -146
- package/lib/src/schema.d.ts +58 -58
- package/lib/src/schema.js +117 -117
- package/package.json +2 -2
package/lib/src/results.d.ts
CHANGED
|
@@ -1,118 +1,118 @@
|
|
|
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
|
+
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>;
|
package/lib/src/results.js
CHANGED
|
@@ -1,146 +1,146 @@
|
|
|
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;
|
|
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;
|
package/lib/src/schema.d.ts
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
import { FieldType } from './grammar';
|
|
2
|
-
export interface ISchemaOptions {
|
|
3
|
-
/**
|
|
4
|
-
* The measurement name this schema is describing.
|
|
5
|
-
*/
|
|
6
|
-
measurement: string;
|
|
7
|
-
/**
|
|
8
|
-
* The database the measurement lives under. Uses the default database
|
|
9
|
-
* if one is provided.
|
|
10
|
-
*/
|
|
11
|
-
database?: string;
|
|
12
|
-
/**
|
|
13
|
-
* Columns is the map of column type definitions on the database.
|
|
14
|
-
*/
|
|
15
|
-
fields: {
|
|
16
|
-
[column: string]: FieldType;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* A list of schema tag names.
|
|
20
|
-
*/
|
|
21
|
-
tags: string[];
|
|
22
|
-
}
|
|
23
|
-
export declare type FieldMap = {
|
|
24
|
-
[name: string]: string | number | boolean;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* The Schema provides information and utilities for an InfluxDB measurement.
|
|
28
|
-
* @private
|
|
29
|
-
*/
|
|
30
|
-
export declare class Schema {
|
|
31
|
-
private options;
|
|
32
|
-
private fieldNames;
|
|
33
|
-
private tagHash;
|
|
34
|
-
constructor(options: ISchemaOptions);
|
|
35
|
-
/**
|
|
36
|
-
* coerceFields converts a map of field values to a strings which
|
|
37
|
-
* can be injected into the line protocol without further escaping.
|
|
38
|
-
* The output is given in [key, value] pairs.
|
|
39
|
-
*/
|
|
40
|
-
coerceFields(fields: FieldMap): [string, string][];
|
|
41
|
-
/**
|
|
42
|
-
* Throws an error if the tags include values other than
|
|
43
|
-
* what was specified in the schema. It returns a list of tag names.
|
|
44
|
-
*/
|
|
45
|
-
checkTags(tags: {
|
|
46
|
-
[tag: string]: string;
|
|
47
|
-
}): string[];
|
|
48
|
-
/**
|
|
49
|
-
* Returns the 'db'.'measurement'[.'field'] referencing the current schema.
|
|
50
|
-
*/
|
|
51
|
-
private ref(field?);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Coerces the field map to a set of writable values, a la coerceFields,
|
|
55
|
-
* using native guesses based on the field datatypes.
|
|
56
|
-
* @private
|
|
57
|
-
*/
|
|
58
|
-
export declare function coerceBadly(fields: FieldMap): [string, string][];
|
|
1
|
+
import { FieldType } from './grammar';
|
|
2
|
+
export interface ISchemaOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The measurement name this schema is describing.
|
|
5
|
+
*/
|
|
6
|
+
measurement: string;
|
|
7
|
+
/**
|
|
8
|
+
* The database the measurement lives under. Uses the default database
|
|
9
|
+
* if one is provided.
|
|
10
|
+
*/
|
|
11
|
+
database?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Columns is the map of column type definitions on the database.
|
|
14
|
+
*/
|
|
15
|
+
fields: {
|
|
16
|
+
[column: string]: FieldType;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* A list of schema tag names.
|
|
20
|
+
*/
|
|
21
|
+
tags: string[];
|
|
22
|
+
}
|
|
23
|
+
export declare type FieldMap = {
|
|
24
|
+
[name: string]: string | number | boolean;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The Schema provides information and utilities for an InfluxDB measurement.
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
30
|
+
export declare class Schema {
|
|
31
|
+
private options;
|
|
32
|
+
private fieldNames;
|
|
33
|
+
private tagHash;
|
|
34
|
+
constructor(options: ISchemaOptions);
|
|
35
|
+
/**
|
|
36
|
+
* coerceFields converts a map of field values to a strings which
|
|
37
|
+
* can be injected into the line protocol without further escaping.
|
|
38
|
+
* The output is given in [key, value] pairs.
|
|
39
|
+
*/
|
|
40
|
+
coerceFields(fields: FieldMap): [string, string][];
|
|
41
|
+
/**
|
|
42
|
+
* Throws an error if the tags include values other than
|
|
43
|
+
* what was specified in the schema. It returns a list of tag names.
|
|
44
|
+
*/
|
|
45
|
+
checkTags(tags: {
|
|
46
|
+
[tag: string]: string;
|
|
47
|
+
}): string[];
|
|
48
|
+
/**
|
|
49
|
+
* Returns the 'db'.'measurement'[.'field'] referencing the current schema.
|
|
50
|
+
*/
|
|
51
|
+
private ref(field?);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Coerces the field map to a set of writable values, a la coerceFields,
|
|
55
|
+
* using native guesses based on the field datatypes.
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
export declare function coerceBadly(fields: FieldMap): [string, string][];
|