@kronos-integration/service-influxdb 1.2.0 → 1.2.2
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kronos-integration/service-influxdb",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@influxdata/influxdb-client": "^1.35.0",
|
|
40
|
-
"@kronos-integration/service": "^13.1.
|
|
41
|
-
"pacc": "^3.
|
|
40
|
+
"@kronos-integration/service": "^13.1.2",
|
|
41
|
+
"pacc": "^3.11.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/node": "^24.1.0",
|
package/src/point-endpoint.mjs
CHANGED
|
@@ -2,29 +2,15 @@ import { Point } from "@influxdata/influxdb-client";
|
|
|
2
2
|
import { ReceiveEndpoint } from "@kronos-integration/endpoint";
|
|
3
3
|
|
|
4
4
|
export class PointEndpoint extends ReceiveEndpoint {
|
|
5
|
-
constructor(name, owner, options) {
|
|
6
|
-
super(name, owner, options);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
get org() {
|
|
10
|
-
return this.owner.org;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
get bucket() {
|
|
14
|
-
return this.owner.bucket;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
get writeClient() {
|
|
18
|
-
return this.owner.client.getWriteApi(this.org, this.bucket, "ns");
|
|
19
|
-
}
|
|
20
|
-
|
|
21
5
|
async receive(value) {
|
|
22
6
|
const num = Number.parseFloat(value.toString());
|
|
23
7
|
|
|
24
|
-
|
|
8
|
+
const [pointName, fieldName] = this.name.split(".");
|
|
9
|
+
|
|
10
|
+
console.log(pointName, fieldName, num);
|
|
25
11
|
|
|
26
|
-
const point = new Point(
|
|
12
|
+
const point = new Point(pointName).floatField(fieldName, num);
|
|
27
13
|
|
|
28
|
-
this.
|
|
14
|
+
this.owner.writeApi.writePoint(point);
|
|
29
15
|
}
|
|
30
16
|
}
|
package/src/service-influxdb.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
} from "pacc";
|
|
7
7
|
import { Service } from "@kronos-integration/service";
|
|
8
8
|
import { InfluxDB } from "@influxdata/influxdb-client";
|
|
9
|
+
import { PointEndpoint } from "./point-endpoint.mjs";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* influxdb client.
|
|
@@ -53,6 +54,14 @@ export class ServiceInfluxdb extends Service {
|
|
|
53
54
|
return `${this.name}(${this.url})`;
|
|
54
55
|
}
|
|
55
56
|
|
|
57
|
+
endpointFactoryFromConfig(name, definition, ic) {
|
|
58
|
+
if (name.indexOf(".") >= 0) {
|
|
59
|
+
return PointEndpoint;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return super.endpointFactoryFromConfig(name, definition, ic);
|
|
63
|
+
}
|
|
64
|
+
|
|
56
65
|
async _start() {
|
|
57
66
|
await super._start();
|
|
58
67
|
|
|
@@ -62,10 +71,12 @@ export class ServiceInfluxdb extends Service {
|
|
|
62
71
|
});
|
|
63
72
|
|
|
64
73
|
this.client = client;
|
|
74
|
+
this.writeApi = client.getWriteApi(this.org, this.bucket);
|
|
65
75
|
}
|
|
66
76
|
|
|
67
77
|
async _stop() {
|
|
68
|
-
|
|
78
|
+
await super._stop();
|
|
79
|
+
return this.writeApi?.close();
|
|
69
80
|
}
|
|
70
81
|
}
|
|
71
82
|
|
package/tests/influxdb-ava.mjs
CHANGED
|
@@ -8,12 +8,20 @@ test("start / stop", async t => {
|
|
|
8
8
|
|
|
9
9
|
const influxdb = await sp.declareService({
|
|
10
10
|
type: ServiceInfluxdb,
|
|
11
|
-
url: "http://localhost:8086"
|
|
11
|
+
url: "http://localhost:8086",
|
|
12
|
+
endpoints: {
|
|
13
|
+
"aPoint.aField": {}
|
|
14
|
+
}
|
|
12
15
|
});
|
|
13
16
|
|
|
14
17
|
await influxdb.start();
|
|
15
18
|
t.is(influxdb.state, "running");
|
|
16
19
|
|
|
20
|
+
t.truthy(influxdb.client);
|
|
21
|
+
t.truthy(influxdb.writeApi);
|
|
22
|
+
|
|
23
|
+
//influxdb.endpoints["aPoint.aField"].receive("1.23");
|
|
24
|
+
|
|
17
25
|
await influxdb.stop();
|
|
18
26
|
t.is(influxdb.state, "stopped");
|
|
19
27
|
});
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
export class PointEndpoint extends ReceiveEndpoint {
|
|
2
|
-
constructor(name: any, owner: any, options: any);
|
|
3
|
-
get org(): any;
|
|
4
|
-
get bucket(): any;
|
|
5
|
-
get writeClient(): any;
|
|
6
2
|
receive(value: any): Promise<void>;
|
|
7
3
|
}
|
|
8
4
|
import { ReceiveEndpoint } from "@kronos-integration/endpoint";
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
* influxdb client.
|
|
3
3
|
*/
|
|
4
4
|
export class ServiceInfluxdb extends Service {
|
|
5
|
+
endpointFactoryFromConfig(name: any, definition: any, ic: any): any;
|
|
5
6
|
client: InfluxDB;
|
|
7
|
+
writeApi: import("@influxdata/influxdb-client").WriteApi;
|
|
6
8
|
}
|
|
7
9
|
export default ServiceInfluxdb;
|
|
8
10
|
import { Service } from "@kronos-integration/service";
|