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 matcher
|
45 | * @return
|
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
|
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: () => Array<{
|
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): Array<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>;
|