@things-factory/integration-influxdb 7.0.0-alpha.30 → 7.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/integration-influxdb",
3
- "version": "7.0.0-alpha.30",
3
+ "version": "7.0.0",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "dist-client/index.js",
6
6
  "things-factory": true,
@@ -27,7 +27,8 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@influxdata/influxdb-client": "^1.33.2",
30
- "@things-factory/integration-base": "^7.0.0-alpha.30"
30
+ "@things-factory/integration-base": "^7.0.0",
31
+ "ses": "^1.5.0"
31
32
  },
32
- "gitHead": "64f2ff6e284ecb26530d1a456a0627dced03fde7"
33
+ "gitHead": "00f3917ca132679e3571f3f4fd16f4caf84f488e"
33
34
  }
@@ -32,13 +32,16 @@ export class InfluxDBConnector implements Connector {
32
32
 
33
33
  ConnectionManager.logger.info(`influxdb connection(${connection.name}:${connection.endpoint}) is connected`)
34
34
  } catch (ex) {
35
- ConnectionManager.logger.info(`influxdb connection(${connection.name}:${connection.endpoint}) failed to connect`)
35
+ ConnectionManager.logger.info(
36
+ `influxdb connection(${connection.name}:${connection.endpoint}) failed to connect`,
37
+ ex
38
+ )
36
39
  throw ex
37
40
  }
38
41
  }
39
42
 
40
43
  async disconnect(connection: Connection) {
41
- var { client } = ConnectionManager.removeConnectionInstance(connection)
44
+ var client = ConnectionManager.removeConnectionInstance(connection)
42
45
  client.close()
43
46
 
44
47
  ConnectionManager.logger.info(`influxdb connection(${connection.name}) is disconnected`)
@@ -1,6 +1,5 @@
1
+ import 'ses'
1
2
  import { InfluxDB, FluxTableMetaData } from '@influxdata/influxdb-client'
2
- import { VM } from 'vm2'
3
-
4
3
  import { ConnectionManager, Context, TaskRegistry } from '@things-factory/integration-base'
5
4
 
6
5
  const debug = require('debug')('things-factory:influxdb-query')
@@ -25,8 +24,7 @@ interface InfluxRaw {
25
24
  }
26
25
 
27
26
  function processInfluxData(raws: InfluxRaw[]): InfluxData[] {
28
- var current: InfluxData
29
- var result: { [time: string]: InfluxData } = {}
27
+ const result: { [time: string]: InfluxData } = {}
30
28
 
31
29
  raws.forEach(raw => {
32
30
  const { _time, _field, _value, _measurement, _start, _stop, result: _result, table, ...tags } = raw
@@ -56,17 +54,21 @@ async function influxdbQuery(step, { domain, user, data, variables, lng }: Conte
56
54
  throw new Error(`no connection : ${connection}`)
57
55
  }
58
56
 
59
- const vm = new VM({
60
- sandbox: {
61
- domain,
62
- user,
63
- lng,
64
- data,
65
- variables
66
- }
57
+ const compartment = new Compartment({
58
+ domain,
59
+ user,
60
+ lng,
61
+ data,
62
+ variables,
63
+ console
67
64
  })
68
65
 
69
- const fluxQuery = vm.run('`' + query + '`')
66
+ let fluxQuery
67
+ try {
68
+ fluxQuery = compartment.evaluate('`' + query + '`')
69
+ } catch (err) {
70
+ throw new Error(`Failed to evaluate query: ${err.message}`)
71
+ }
70
72
 
71
73
  const queryApi = client.getQueryApi(organization)
72
74
 
@@ -86,7 +88,14 @@ influxdbQuery.parameterSpec = [
86
88
  {
87
89
  type: 'textarea',
88
90
  name: 'query',
89
- label: 'influxdb.query'
91
+ label: 'influxdb.query',
92
+ property: {
93
+ language: 'text',
94
+ showLineNumbers: true
95
+ },
96
+ styles: {
97
+ flex: '1'
98
+ }
90
99
  }
91
100
  ]
92
101