influx 5.10.0 → 5.12.0
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/index.d.ts +4 -0
- package/lib/src/index.js +14 -10
- package/lib/src/pool.d.ts +13 -0
- package/lib/src/pool.js +24 -3
- package/package.json +1 -1
package/lib/src/index.d.ts
CHANGED
|
@@ -161,6 +161,10 @@ export interface IQueryOptions {
|
|
|
161
161
|
* Execute a query as a HTTP GET or POST request
|
|
162
162
|
*/
|
|
163
163
|
method?: "GET" | "POST";
|
|
164
|
+
/**
|
|
165
|
+
* Abort Signal to cancel the query request
|
|
166
|
+
*/
|
|
167
|
+
signal?: AbortSignal;
|
|
164
168
|
}
|
|
165
169
|
export interface IParseOptions {
|
|
166
170
|
/**
|
package/lib/src/index.js
CHANGED
|
@@ -858,11 +858,12 @@ class InfluxDB {
|
|
|
858
858
|
path: "/write",
|
|
859
859
|
query: {
|
|
860
860
|
db: database,
|
|
861
|
-
p: this._options.password,
|
|
862
861
|
precision,
|
|
863
862
|
rp: retentionPolicy,
|
|
864
|
-
u: this._options.username,
|
|
865
863
|
},
|
|
864
|
+
auth: typeof this._options.username === "string"
|
|
865
|
+
? `${this._options.username}:${this._options.password || ""}`
|
|
866
|
+
: undefined,
|
|
866
867
|
});
|
|
867
868
|
}
|
|
868
869
|
/**
|
|
@@ -999,7 +1000,7 @@ class InfluxDB {
|
|
|
999
1000
|
q: query,
|
|
1000
1001
|
rp: retentionPolicy,
|
|
1001
1002
|
params: JSON.stringify(placeholders),
|
|
1002
|
-
}, options.method, true));
|
|
1003
|
+
}, options.method, true, options.signal));
|
|
1003
1004
|
}
|
|
1004
1005
|
/**
|
|
1005
1006
|
* Pings all available hosts, collecting online status and version info.
|
|
@@ -1039,24 +1040,27 @@ class InfluxDB {
|
|
|
1039
1040
|
* Creates options to be passed into the pool to query databases.
|
|
1040
1041
|
* @private
|
|
1041
1042
|
*/
|
|
1042
|
-
_getQueryOpts(params, method = "GET", partOfBody = false) {
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
}
|
|
1043
|
+
_getQueryOpts(params, method = "GET", partOfBody = false, signal = undefined) {
|
|
1044
|
+
let auth = undefined;
|
|
1045
|
+
if (typeof this._options.username === "string") {
|
|
1046
|
+
auth = `${this._options.username}:${this._options.password || ""}`;
|
|
1047
|
+
}
|
|
1047
1048
|
if (method === "POST" && partOfBody) {
|
|
1048
1049
|
return {
|
|
1049
1050
|
method,
|
|
1051
|
+
signal,
|
|
1050
1052
|
path: "/query",
|
|
1051
|
-
|
|
1053
|
+
auth,
|
|
1052
1054
|
body: querystring.stringify(params),
|
|
1053
1055
|
};
|
|
1054
1056
|
}
|
|
1055
1057
|
else {
|
|
1056
1058
|
return {
|
|
1057
1059
|
method,
|
|
1060
|
+
signal,
|
|
1058
1061
|
path: "/query",
|
|
1059
|
-
|
|
1062
|
+
auth,
|
|
1063
|
+
query: Object.assign({}, params),
|
|
1060
1064
|
};
|
|
1061
1065
|
}
|
|
1062
1066
|
}
|
package/lib/src/pool.d.ts
CHANGED
|
@@ -43,6 +43,19 @@ export interface IPoolRequestOptions {
|
|
|
43
43
|
* running this request.
|
|
44
44
|
*/
|
|
45
45
|
retries?: number;
|
|
46
|
+
/**
|
|
47
|
+
* Optional Basic auth in the form `username:password`.
|
|
48
|
+
* When provided, Pool will set the `Authorization: Basic ...` header.
|
|
49
|
+
*/
|
|
50
|
+
auth?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Optional extra headers to include in the request.
|
|
53
|
+
*/
|
|
54
|
+
headers?: http.OutgoingHttpHeaders;
|
|
55
|
+
/**
|
|
56
|
+
* Optional abort signal to cancel the request.
|
|
57
|
+
*/
|
|
58
|
+
signal?: AbortSignal;
|
|
46
59
|
}
|
|
47
60
|
/**
|
|
48
61
|
* An ServiceNotAvailableError is returned as an error from requests that
|
package/lib/src/pool.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
14
|
exports.Pool = exports.RequestError = exports.ServiceNotAvailableError = void 0;
|
|
4
15
|
const exponential_1 = require("./backoff/exponential");
|
|
@@ -241,9 +252,19 @@ class Pool {
|
|
|
241
252
|
if (options.query) {
|
|
242
253
|
path += "?" + querystring.stringify(options.query);
|
|
243
254
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
255
|
+
// Merge headers from defaults, host options, and call options.
|
|
256
|
+
const hostHeaders = (host.options && host.options.headers) || {};
|
|
257
|
+
const defaultHeaders = Object.assign({ "content-length": options.body ? Buffer.from(options.body).length : 0 }, (options.body && options.path === "/query"
|
|
258
|
+
? { "Content-Type": "application/x-www-form-urlencoded" }
|
|
259
|
+
: {}));
|
|
260
|
+
const mergedHeaders = Object.assign(Object.assign(Object.assign({}, hostHeaders), defaultHeaders), (options.headers || {}));
|
|
261
|
+
if (typeof options.auth !== "undefined") {
|
|
262
|
+
const encodedAuth = Buffer.from(options.auth).toString("base64");
|
|
263
|
+
mergedHeaders["Authorization"] = `Basic ${encodedAuth}`;
|
|
264
|
+
}
|
|
265
|
+
const _a = (host.options ||
|
|
266
|
+
{}), { headers: _ignoredHostHeaders } = _a, hostReqOptions = __rest(_a, ["headers"]);
|
|
267
|
+
const req = request(Object.assign({ headers: mergedHeaders, hostname: host.url.hostname, method: options.method, signal: options.signal, path, port: Number(host.url.port), protocol: host.url.protocol, timeout: this._timeout }, hostReqOptions), once((res) => {
|
|
247
268
|
res.setEncoding("utf8");
|
|
248
269
|
if (res.statusCode >= 500) {
|
|
249
270
|
res.on("data", () => {
|