node-red-contrib-influxdb3 1.0.6 → 1.0.8
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/README.md +6 -5
- package/influxdb3.html +2 -2
- package/influxdb3.js +57 -45
- package/lib/line-protocol.js +41 -0
- package/package.json +14 -2
- package/__tests__/influxdb3.test.js +0 -972
- package/renovate.json +0 -6
- package/test/line-protocol-validation.test.js +0 -83
- package/test/point-api.test.js +0 -56
package/renovate.json
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for line protocol string validation.
|
|
3
|
-
* Mirrors the validateLineProtocol logic in influxdb3.js.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// Re-implement the validation logic here to test it in isolation
|
|
7
|
-
// (the function is not exported from influxdb3.js)
|
|
8
|
-
function validateLineProtocol(lp) {
|
|
9
|
-
if (/^\{[\s\S]*}$/.test(lp) || /^\[[\s\S]*]$/.test(lp)) {
|
|
10
|
-
const preview = lp.length > 100 ? lp.substring(0, 100) + '...' : lp;
|
|
11
|
-
return (
|
|
12
|
-
'The payload appears to be a JSON/object string, not line protocol. ' +
|
|
13
|
-
'If you are sending JSON, ensure msg.payload is a parsed object (not a string). ' +
|
|
14
|
-
'Use a JSON parse node before this node to convert the string to an object. ' +
|
|
15
|
-
`Received string: ${preview}`
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (!lp.includes(' ') || !lp.includes('=')) {
|
|
20
|
-
const preview = lp.length > 100 ? lp.substring(0, 100) + '...' : lp;
|
|
21
|
-
return (
|
|
22
|
-
'The payload string does not appear to be valid line protocol. ' +
|
|
23
|
-
'Expected format: measurement[,tag=val] field=val[,field=val] [timestamp]. ' +
|
|
24
|
-
`Received: ${preview}`
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
describe('Line protocol string validation', () => {
|
|
32
|
-
test('valid line protocol returns null', () => {
|
|
33
|
-
expect(validateLineProtocol('weather,location=us-midwest temperature=82 1465839830100400200')).toBeNull();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('valid line protocol without timestamp returns null', () => {
|
|
37
|
-
expect(validateLineProtocol('weather,location=us-midwest temperature=82')).toBeNull();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test('valid line protocol without tags returns null', () => {
|
|
41
|
-
expect(validateLineProtocol('weather temperature=82')).toBeNull();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('valid line protocol with multiple fields returns null', () => {
|
|
45
|
-
expect(validateLineProtocol('weather temperature=82,humidity=71')).toBeNull();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('detects JSON object string', () => {
|
|
49
|
-
const input = '{"fields":{"used":12.0},"tags":{"location":"office"}}';
|
|
50
|
-
const result = validateLineProtocol(input);
|
|
51
|
-
expect(result).toContain('JSON/object string');
|
|
52
|
-
expect(result).toContain('not line protocol');
|
|
53
|
-
expect(result).toContain('JSON parse node');
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('detects JS object notation string (unquoted keys)', () => {
|
|
57
|
-
const input = '{fields:{used:12.0,path:root},tags:{location:office,node:grafana2}}';
|
|
58
|
-
const result = validateLineProtocol(input);
|
|
59
|
-
expect(result).toContain('JSON/object string');
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('detects JSON array string', () => {
|
|
63
|
-
const input = '[{"measurement":"test","fields":{"value":1}}]';
|
|
64
|
-
const result = validateLineProtocol(input);
|
|
65
|
-
expect(result).toContain('JSON/object string');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test('detects string with no space (not line protocol)', () => {
|
|
69
|
-
const result = validateLineProtocol('justameasurement');
|
|
70
|
-
expect(result).toContain('does not appear to be valid line protocol');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test('detects string with no equals sign (not line protocol)', () => {
|
|
74
|
-
const result = validateLineProtocol('measurement nofields');
|
|
75
|
-
expect(result).toContain('does not appear to be valid line protocol');
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test('truncates long strings in error message', () => {
|
|
79
|
-
const longJson = '{' + '"a":1,'.repeat(50) + '"b":2}';
|
|
80
|
-
const result = validateLineProtocol(longJson);
|
|
81
|
-
expect(result).toContain('...');
|
|
82
|
-
});
|
|
83
|
-
});
|
package/test/point-api.test.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
const { Point } = require('@influxdata/influxdb3-client');
|
|
2
|
-
|
|
3
|
-
describe('@influxdata/influxdb3-client v2.x Point API', () => {
|
|
4
|
-
test('Point.setField exists and is a function', () => {
|
|
5
|
-
const point = new Point('test');
|
|
6
|
-
expect(typeof point.setField).toBe('function');
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
test('Point.setField accepts (name, value) for float', () => {
|
|
10
|
-
const point = new Point('test');
|
|
11
|
-
point.setField('temp', 23.5);
|
|
12
|
-
const lp = point.toLineProtocol();
|
|
13
|
-
expect(lp).toContain('temp=23.5');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test('Point.setField accepts (name, value, "integer") for integer', () => {
|
|
17
|
-
const point = new Point('test');
|
|
18
|
-
point.setField('count', 42, 'integer');
|
|
19
|
-
const lp = point.toLineProtocol();
|
|
20
|
-
expect(lp).toContain('count=42i');
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('Point.setField accepts (name, value) for string', () => {
|
|
24
|
-
const point = new Point('test');
|
|
25
|
-
point.setField('status', 'ok');
|
|
26
|
-
const lp = point.toLineProtocol();
|
|
27
|
-
expect(lp).toContain('status="ok"');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('Point.setField accepts (name, value) for boolean', () => {
|
|
31
|
-
const point = new Point('test');
|
|
32
|
-
point.setField('active', true);
|
|
33
|
-
const lp = point.toLineProtocol();
|
|
34
|
-
// Library serializes booleans as T/F in line protocol
|
|
35
|
-
expect(lp).toContain('active=T');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('Point.setTag exists and is a function', () => {
|
|
39
|
-
const point = new Point('test');
|
|
40
|
-
expect(typeof point.setTag).toBe('function');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test('Point.setTimestamp exists and is a function', () => {
|
|
44
|
-
const point = new Point('test');
|
|
45
|
-
expect(typeof point.setTimestamp).toBe('function');
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('type-specific methods exist alongside generic setField', () => {
|
|
49
|
-
const point = new Point('test');
|
|
50
|
-
expect(typeof point.setIntegerField).toBe('function');
|
|
51
|
-
expect(typeof point.setFloatField).toBe('function');
|
|
52
|
-
expect(typeof point.setStringField).toBe('function');
|
|
53
|
-
expect(typeof point.setBooleanField).toBe('function');
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|