@things-factory/integration-influxdb 7.0.0-alpha.13

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.
Files changed (50) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +0 -0
  3. package/client/bootstrap.ts +9 -0
  4. package/client/editors/property-editor.ts +20 -0
  5. package/client/editors/things-editor-influxdb-point-scheme.ts +305 -0
  6. package/client/index.ts +0 -0
  7. package/dist-server/engine/connector/index.js +4 -0
  8. package/dist-server/engine/connector/index.js.map +1 -0
  9. package/dist-server/engine/connector/influxdb.js +56 -0
  10. package/dist-server/engine/connector/influxdb.js.map +1 -0
  11. package/dist-server/engine/index.js +5 -0
  12. package/dist-server/engine/index.js.map +1 -0
  13. package/dist-server/engine/task/index.js +5 -0
  14. package/dist-server/engine/task/index.js.map +1 -0
  15. package/dist-server/engine/task/influxdb-query.js +59 -0
  16. package/dist-server/engine/task/influxdb-query.js.map +1 -0
  17. package/dist-server/engine/task/influxdb-write-point.js +70 -0
  18. package/dist-server/engine/task/influxdb-write-point.js.map +1 -0
  19. package/dist-server/index.js +4 -0
  20. package/dist-server/index.js.map +1 -0
  21. package/dist-server/tsconfig.tsbuildinfo +1 -0
  22. package/helps/integration/connector/influxdb-connector.ja.md +17 -0
  23. package/helps/integration/connector/influxdb-connector.ko.md +17 -0
  24. package/helps/integration/connector/influxdb-connector.md +17 -0
  25. package/helps/integration/connector/influxdb-connector.ms.md +17 -0
  26. package/helps/integration/connector/influxdb-connector.zh.md +17 -0
  27. package/helps/integration/task/influxdb-query.ja.md +15 -0
  28. package/helps/integration/task/influxdb-query.ko.md +15 -0
  29. package/helps/integration/task/influxdb-query.md +15 -0
  30. package/helps/integration/task/influxdb-query.ms.md +15 -0
  31. package/helps/integration/task/influxdb-query.zh.md +15 -0
  32. package/helps/integration/task/influxdb-write-point.ja.md +28 -0
  33. package/helps/integration/task/influxdb-write-point.ko.md +28 -0
  34. package/helps/integration/task/influxdb-write-point.md +28 -0
  35. package/helps/integration/task/influxdb-write-point.ms.md +28 -0
  36. package/helps/integration/task/influxdb-write-point.zh.md +28 -0
  37. package/package.json +32 -0
  38. package/server/engine/connector/index.ts +1 -0
  39. package/server/engine/connector/influxdb.ts +66 -0
  40. package/server/engine/index.ts +2 -0
  41. package/server/engine/task/index.ts +2 -0
  42. package/server/engine/task/influxdb-query.ts +95 -0
  43. package/server/engine/task/influxdb-write-point.ts +89 -0
  44. package/server/index.ts +1 -0
  45. package/things-factory.config.js +5 -0
  46. package/translations/en.json +7 -0
  47. package/translations/ja.json +7 -0
  48. package/translations/ko.json +7 -0
  49. package/translations/ms.json +7 -0
  50. package/translations/zh.json +7 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6
+ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7
+
8
+ <!-- ## [Unreleased] -->
package/README.md ADDED
File without changes
@@ -0,0 +1,9 @@
1
+ import { OxPropertyEditor } from '@operato/property-editor'
2
+
3
+ import './editors/property-editor'
4
+
5
+ export default function bootstrap() {
6
+ OxPropertyEditor.register({
7
+ 'influxdb-point-scheme': 'property-editor-influxdb-point-scheme'
8
+ })
9
+ }
@@ -0,0 +1,20 @@
1
+ /*
2
+ * Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+ import './things-editor-influxdb-point-scheme'
5
+
6
+ import { html } from 'lit'
7
+
8
+ import { OxPropertyEditor } from '@operato/property-editor'
9
+
10
+ export class PropertyEditorInfluxDBScheme extends OxPropertyEditor {
11
+ static get styles() {
12
+ return [...OxPropertyEditor.styles]
13
+ }
14
+
15
+ editorTemplate(value, spec) {
16
+ return html` <things-editor-influxdb-point-scheme id="editor" .value=${value}></things-editor-influxdb-point-scheme> `
17
+ }
18
+ }
19
+
20
+ customElements.define('property-editor-influxdb-point-scheme', PropertyEditorInfluxDBScheme)
@@ -0,0 +1,305 @@
1
+ /**
2
+ * @license Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+
5
+ import '@material/mwc-icon'
6
+
7
+ import '@operato/i18n/ox-i18n.js'
8
+ import { css, html } from 'lit'
9
+ import { customElement, property, queryAll } from 'lit/decorators.js'
10
+
11
+ import { OxFormField } from '@operato/input'
12
+
13
+ type InfluxDBPointScheme = {
14
+ name: string
15
+ type: string
16
+ val?: any
17
+ accessor?: string
18
+ }
19
+
20
+ /**
21
+ input component for influxdb point scheme
22
+
23
+ Example:
24
+
25
+ <things-editor-influxdb-point-scheme
26
+ value=${map}
27
+ </things-editor-influxdb-point-scheme>
28
+ */
29
+ @customElement('things-editor-influxdb-point-scheme')
30
+ export class ThingsEditorProcedureParameters extends OxFormField {
31
+ static styles = [
32
+ css`
33
+ :host {
34
+ display: flex;
35
+ flex-direction: column;
36
+ overflow: hidden;
37
+ margin-bottom: var(--margin-wide);
38
+ }
39
+
40
+ div {
41
+ display: flex;
42
+ flex-flow: row nowrap;
43
+ gap: var(--margin-default);
44
+ margin-bottom: var(--margin-narrow);
45
+ }
46
+
47
+ button {
48
+ border: var(--button-border);
49
+ border-radius: var(--border-radius);
50
+ background-color: var(--button-background-color);
51
+ padding: var(--padding-narrow) var(--padding-default);
52
+ line-height: 0.8;
53
+ color: var(--button-color);
54
+ cursor: pointer;
55
+ }
56
+
57
+ button + button {
58
+ margin-left: -5px;
59
+ }
60
+
61
+ button mwc-icon {
62
+ font-size: var(--fontsize-default);
63
+ }
64
+
65
+ button:focus,
66
+ button:hover,
67
+ button:active {
68
+ border: var(--button-activ-border);
69
+ background-color: var(--button-background-focus-color);
70
+ color: var(--theme-white-color);
71
+ }
72
+
73
+ input {
74
+ flex: 1;
75
+ border: 0;
76
+ border-bottom: var(--border-dark-color);
77
+ padding: var(--input-padding);
78
+ font: var(--input-font);
79
+ color: var(--primary-text-color);
80
+ min-width: 50px;
81
+ }
82
+
83
+ input:focus {
84
+ outline: none;
85
+ border-bottom: 1px solid var(--primary-color);
86
+ }
87
+
88
+ button.hidden {
89
+ opacity: 0;
90
+ cursor: default;
91
+ }
92
+
93
+ select,
94
+ ox-select,
95
+ input:not([type='checkbox']) {
96
+ border: 1px solid rgba(0, 0, 0, 0.2);
97
+ border-radius: 4px;
98
+ }
99
+ `
100
+ ]
101
+
102
+ @property({ type: Array }) value: InfluxDBPointScheme[] = []
103
+
104
+ private _changingNow: boolean = false
105
+
106
+ @queryAll('[data-record]') records!: NodeListOf<HTMLElement>
107
+
108
+ firstUpdated() {
109
+ this.renderRoot.addEventListener('change', this._onChange.bind(this))
110
+ }
111
+
112
+ render() {
113
+ const parameters = this.value || []
114
+
115
+ return html`
116
+ ${parameters.map(
117
+ item => html`
118
+ <div data-record>
119
+ <input type="text" data-name placeholder="name" .value=${item.name} />
120
+ <select data-type placeholder="type" .value=${item.type}>
121
+ <option value="" ?selected=${item.type == ''}>&nbsp;</option>
122
+ <option value="Tag" ?selected=${item.type == 'Tag'}>Tag</option>
123
+ <option value="String" ?selected=${item.type == 'String'}>String</option>
124
+ <option value="Integer" ?selected=${item.type == 'Integer'}>Integer</option>
125
+ <option value="Unsigned" ?selected=${item.type == 'Unsigned'}>Unsigned</option>
126
+ <option value="Float" ?selected=${item.type == 'Float'}>Float</option>
127
+ <option value="Boolean" ?selected=${item.type == 'Boolean'}>Boolean</option>
128
+ </select>
129
+
130
+ <input type="text" data-accessor placeholder="accessor" .value=${item.accessor || ''} list="step-list" />
131
+ <input type="text" data-val placeholder="val" .value=${item.val || ''} />
132
+
133
+ <button class="record-action" @click=${(e: MouseEvent) => this._delete(e)} tabindex="-1">
134
+ <mwc-icon>remove</mwc-icon>
135
+ </button>
136
+ <button class="record-action" @click=${(e: MouseEvent) => this._up(e)} tabindex="-1">
137
+ <mwc-icon>arrow_upward</mwc-icon>
138
+ </button>
139
+ <button class="record-action" @click=${(e: MouseEvent) => this._down(e)} tabindex="-1">
140
+ <mwc-icon>arrow_downward</mwc-icon>
141
+ </button>
142
+ </div>
143
+ `
144
+ )}
145
+
146
+ <div data-record-new>
147
+ <input type="text" data-name placeholder="name" value="" />
148
+ <select data-type placeholder="type" value="">
149
+ <option value="" selected>&nbsp;</option>
150
+ <option value="Tag">Tag</option>
151
+ <option value="String">String</option>
152
+ <option value="Integer">Integer</option>
153
+ <option value="Unsigned">Unsigned</option>
154
+ <option value="Float">Float</option>
155
+ <option value="Boolean">Boolean</option>
156
+ </select>
157
+ <input type="text" data-accessor placeholder="accessor" value="" list="step-list" />
158
+ <input type="text" data-val placeholder="val" value="" />
159
+
160
+ <button class="record-action" @click=${(e: MouseEvent) => this._add()} tabindex="-1">
161
+ <mwc-icon>add</mwc-icon>
162
+ </button>
163
+ <button class="hidden"><mwc-icon>arrow_upward</mwc-icon></button>
164
+ <button class="hidden"><mwc-icon>arrow_downward</mwc-icon></button>
165
+ </div>
166
+ `
167
+ }
168
+
169
+ _onChange(e: Event) {
170
+ if (this._changingNow) {
171
+ return
172
+ }
173
+
174
+ this._changingNow = true
175
+
176
+ const input = e.target as HTMLInputElement
177
+
178
+ const record = (e.target as Element).closest('[data-record],[data-record-new]') as HTMLElement
179
+
180
+ if (record.hasAttribute('data-record')) {
181
+ this._build()
182
+ } else if (record.hasAttribute('data-record-new') && input.hasAttribute('data-type')) {
183
+ this._add()
184
+ }
185
+
186
+ this._changingNow = false
187
+ }
188
+
189
+ _adjust({ name, type, val, accessor }: InfluxDBPointScheme): InfluxDBPointScheme {
190
+ const entry = {
191
+ name: name && String(name).trim(),
192
+ type,
193
+ accessor: accessor && String(accessor).trim(),
194
+ val
195
+ } as InfluxDBPointScheme
196
+
197
+ return entry
198
+ }
199
+
200
+ _build(includeNewRecord?: boolean) {
201
+ if (includeNewRecord) {
202
+ var records = this.renderRoot.querySelectorAll('[data-record],[data-record-new]') as NodeListOf<HTMLElement>
203
+ } else {
204
+ var records = this.renderRoot.querySelectorAll('[data-record]') as NodeListOf<HTMLElement>
205
+ }
206
+
207
+ var newmap: InfluxDBPointScheme[] = []
208
+
209
+ for (var i = 0; i < records.length; i++) {
210
+ var record = records[i]
211
+
212
+ const name = (record.querySelector('[data-name]') as HTMLInputElement).value
213
+ const type = (record.querySelector('[data-type]') as HTMLInputElement).value
214
+ const val = (record.querySelector('[data-val]') as HTMLInputElement).value
215
+ const accessor = (record.querySelector('[data-accessor]') as HTMLInputElement).value
216
+
217
+ const inputs = record.querySelectorAll('[data-type]:not([style*="display: none"])') as NodeListOf<HTMLInputElement>
218
+
219
+ if (!inputs || inputs.length == 0) {
220
+ continue
221
+ }
222
+
223
+ if (name) {
224
+ newmap.push(this._adjust({ name, type, val, accessor }))
225
+ }
226
+ }
227
+
228
+ this.value = newmap
229
+ this._updateValue()
230
+ }
231
+
232
+ _updateValue() {
233
+ this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
234
+ }
235
+
236
+ _add() {
237
+ this._build(true)
238
+
239
+ const inputs = this.renderRoot.querySelectorAll('[data-record-new] input:not([style*="display: none"])') as NodeListOf<HTMLInputElement & { value: any }>
240
+
241
+ for (var i = 0; i < inputs.length; i++) {
242
+ let input = inputs[i]
243
+
244
+ input.value = ''
245
+ }
246
+
247
+ inputs[0].focus()
248
+ }
249
+
250
+ _delete(e: MouseEvent) {
251
+ const record = (e.target as Element).closest('[data-record]') as HTMLElement
252
+
253
+ ;(record!.querySelector('[data-name]') as HTMLInputElement)!.value = ''
254
+
255
+ this._build()
256
+ }
257
+
258
+ _up(e: MouseEvent) {
259
+ const record = (e.target as Element).closest('[data-record]') as HTMLElement
260
+ const array = Array.from(this.records)
261
+ const index = array.indexOf(record) - 1
262
+
263
+ if (index < 0) {
264
+ return
265
+ }
266
+
267
+ const deleted = array.splice(index, 1)
268
+ array.splice(index + 1, 0, ...deleted)
269
+
270
+ this.value = array.map(record => {
271
+ const name = (record.querySelector('[data-name]') as HTMLInputElement).value
272
+ const type = (record.querySelector('[data-type]') as HTMLInputElement).value
273
+ const val = (record.querySelector('[data-val]') as HTMLInputElement).value
274
+ const accessor = (record.querySelector('[data-accessor]') as HTMLInputElement).value
275
+
276
+ return this._adjust({ name, type, val, accessor })
277
+ })
278
+
279
+ this._updateValue()
280
+ }
281
+
282
+ _down(e: MouseEvent) {
283
+ const record = (e.target as Element).closest('[data-record]') as HTMLElement
284
+ const array = Array.from(this.records)
285
+ const index = array.indexOf(record)
286
+
287
+ if (index > array.length) {
288
+ return
289
+ }
290
+
291
+ array.splice(index, 1)
292
+ array.splice(index + 1, 0, record)
293
+
294
+ this.value = array.map(record => {
295
+ const name = (record.querySelector('[data-name]') as HTMLInputElement).value
296
+ const type = (record.querySelector('[data-type]') as HTMLInputElement).value
297
+ const val = (record.querySelector('[data-val]') as HTMLInputElement).value
298
+ const accessor = (record.querySelector('[data-accessor]') as HTMLInputElement).value
299
+
300
+ return this._adjust({ name, type, val, accessor })
301
+ })
302
+
303
+ this._updateValue()
304
+ }
305
+ }
File without changes
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("./influxdb");
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/engine/connector/index.ts"],"names":[],"mappings":";;AAAA,sBAAmB","sourcesContent":["import './influxdb'\n"]}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InfluxDBConnector = void 0;
4
+ const influxdb_client_1 = require("@influxdata/influxdb-client");
5
+ const integration_base_1 = require("@things-factory/integration-base");
6
+ class InfluxDBConnector {
7
+ async ready(connectionConfigs) {
8
+ await Promise.all(connectionConfigs.map(this.connect.bind(this)));
9
+ integration_base_1.ConnectionManager.logger.info('influxdb connections are ready');
10
+ }
11
+ checkConnectionInstance(domain, connectionName) {
12
+ var _a;
13
+ try {
14
+ const connection = integration_base_1.ConnectionManager.getConnectionInstanceByName(domain, connectionName);
15
+ return !!(((_a = connection === null || connection === void 0 ? void 0 : connection.client) === null || _a === void 0 ? void 0 : _a.connectionState) !== 'online');
16
+ }
17
+ catch (e) {
18
+ return false;
19
+ }
20
+ }
21
+ async connect(connection) {
22
+ var { endpoint, params: { token } } = connection;
23
+ try {
24
+ const client = new influxdb_client_1.InfluxDB({ url: endpoint, token });
25
+ integration_base_1.ConnectionManager.addConnectionInstance(connection, client);
26
+ integration_base_1.ConnectionManager.logger.info(`influxdb connection(${connection.name}:${connection.endpoint}) is connected`);
27
+ }
28
+ catch (ex) {
29
+ integration_base_1.ConnectionManager.logger.info(`influxdb connection(${connection.name}:${connection.endpoint}) failed to connect`);
30
+ throw ex;
31
+ }
32
+ }
33
+ async disconnect(connection) {
34
+ var { client } = integration_base_1.ConnectionManager.removeConnectionInstance(connection);
35
+ client.close();
36
+ integration_base_1.ConnectionManager.logger.info(`influxdb connection(${connection.name}) is disconnected`);
37
+ }
38
+ get parameterSpec() {
39
+ return [
40
+ {
41
+ type: 'string',
42
+ name: 'token',
43
+ label: 'token'
44
+ }
45
+ ];
46
+ }
47
+ get taskPrefixes() {
48
+ return ['influxdb'];
49
+ }
50
+ get help() {
51
+ return 'integration/connector/influxdb-connector';
52
+ }
53
+ }
54
+ exports.InfluxDBConnector = InfluxDBConnector;
55
+ integration_base_1.ConnectionManager.registerConnector('influxdb', new InfluxDBConnector());
56
+ //# sourceMappingURL=influxdb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"influxdb.js","sourceRoot":"","sources":["../../../server/engine/connector/influxdb.ts"],"names":[],"mappings":";;;AAAA,iEAAsD;AAEtD,uEAA2F;AAE3F,MAAa,iBAAiB;IAC5B,KAAK,CAAC,KAAK,CAAC,iBAAiB;QAC3B,MAAM,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAEjE,oCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,g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;QACf,OAAO;YACL;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,OAAO;aACf;SACF,CAAA;IACH,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,UAAU,CAAC,CAAA;IACrB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,0CAA0C,CAAA;IACnD,CAAC;CACF;AA3DD,8CA2DC;AAED,oCAAiB,CAAC,iBAAiB,CAAC,UAAU,EAAE,IAAI,iBAAiB,EAAE,CAAC,CAAA","sourcesContent":["import { InfluxDB } from '@influxdata/influxdb-client'\n\nimport { Connection, ConnectionManager, Connector } from '@things-factory/integration-base'\n\nexport class InfluxDBConnector implements Connector {\n async ready(connectionConfigs) {\n await Promise.all(connectionConfigs.map(this.connect.bind(this)))\n\n ConnectionManager.logger.info('influxdb connections are ready')\n }\n\n checkConnectionInstance(domain, connectionName): boolean {\n try {\n const connection = ConnectionManager.getConnectionInstanceByName(domain, connectionName)\n\n return !!(connection?.client?.connectionState !== 'online')\n } catch (e) {\n return false\n }\n }\n\n async connect(connection) {\n var {\n endpoint,\n params: { token }\n } = connection\n\n try {\n const client = new InfluxDB({ url: endpoint, token })\n\n ConnectionManager.addConnectionInstance(connection, client)\n\n ConnectionManager.logger.info(`influxdb connection(${connection.name}:${connection.endpoint}) is connected`)\n } catch (ex) {\n ConnectionManager.logger.info(`influxdb connection(${connection.name}:${connection.endpoint}) failed to connect`)\n throw ex\n }\n }\n\n async disconnect(connection: Connection) {\n var { client } = ConnectionManager.removeConnectionInstance(connection)\n client.close()\n\n ConnectionManager.logger.info(`influxdb connection(${connection.name}) is disconnected`)\n }\n\n get parameterSpec() {\n return [\n {\n type: 'string',\n name: 'token',\n label: 'token'\n }\n ]\n }\n\n get taskPrefixes() {\n return ['influxdb']\n }\n\n get help() {\n return 'integration/connector/influxdb-connector'\n }\n}\n\nConnectionManager.registerConnector('influxdb', new InfluxDBConnector())\n"]}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("./connector");
4
+ require("./task");
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/engine/index.ts"],"names":[],"mappings":";;AAAA,uBAAoB;AACpB,kBAAe","sourcesContent":["import './connector'\nimport './task'\n"]}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("./influxdb-write-point");
4
+ require("./influxdb-query");
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/engine/task/index.ts"],"names":[],"mappings":";;AAAA,kCAA+B;AAC/B,4BAAyB","sourcesContent":["import './influxdb-write-point'\nimport './influxdb-query'\n"]}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const vm2_1 = require("vm2");
5
+ const integration_base_1 = require("@things-factory/integration-base");
6
+ const debug = require('debug')('things-factory:influxdb-query');
7
+ function processInfluxData(raws) {
8
+ var current;
9
+ var result = {};
10
+ raws.forEach(raw => {
11
+ const { _time, _field, _value, _measurement, _start, _stop, result: _result, table } = raw, tags = tslib_1.__rest(raw, ["_time", "_field", "_value", "_measurement", "_start", "_stop", "result", "table"]);
12
+ result[_time] || (result[_time] = {
13
+ timestamp: _time,
14
+ measurement: _measurement,
15
+ tags,
16
+ fields: {}
17
+ });
18
+ result[_time].fields[_field] = _value;
19
+ });
20
+ return Object.values(result);
21
+ }
22
+ async function influxdbQuery(step, { domain, user, data, variables, lng }) {
23
+ const { connection, params: { organization, query } } = step;
24
+ const client = integration_base_1.ConnectionManager.getConnectionInstanceByName(domain, connection);
25
+ if (!client) {
26
+ debug(`no connection : ${connection}`);
27
+ throw new Error(`no connection : ${connection}`);
28
+ }
29
+ const vm = new vm2_1.VM({
30
+ sandbox: {
31
+ domain,
32
+ user,
33
+ lng,
34
+ data,
35
+ variables
36
+ }
37
+ });
38
+ const fluxQuery = vm.run('`' + query + '`');
39
+ const queryApi = client.getQueryApi(organization);
40
+ const result = await queryApi.collectRows(fluxQuery);
41
+ return {
42
+ data: processInfluxData(result)
43
+ };
44
+ }
45
+ influxdbQuery.parameterSpec = [
46
+ {
47
+ type: 'string',
48
+ name: 'organization',
49
+ label: 'influxdb.organization'
50
+ },
51
+ {
52
+ type: 'textarea',
53
+ name: 'query',
54
+ label: 'influxdb.query'
55
+ }
56
+ ];
57
+ influxdbQuery.help = 'integration/task/influxdb-query';
58
+ integration_base_1.TaskRegistry.registerTaskHandler('influxdb-query', influxdbQuery);
59
+ //# sourceMappingURL=influxdb-query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"influxdb-query.js","sourceRoot":"","sources":["../../../server/engine/task/influxdb-query.ts"],"names":[],"mappings":";;;AACA,6BAAwB;AAExB,uEAA2F;AAE3F,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,+BAA+B,CAAC,CAAA;AAqB/D,SAAS,iBAAiB,CAAC,IAAiB;IAC1C,IAAI,OAAmB,CAAA;IACvB,IAAI,MAAM,GAAmC,EAAE,CAAA;IAE/C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACjB,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,KAAc,GAAG,EAAZ,IAAI,kBAAK,GAAG,EAA7F,mFAAuF,CAAM,CAAA;QAEnG,MAAM,CAAC,KAAK,MAAZ,MAAM,CAAC,KAAK,IAAM;YAChB,SAAS,EAAE,KAAK;YAChB,WAAW,EAAE,YAAY;YACzB,IAAI;YACJ,MAAM,EAAE,EAAE;SACX,EAAA;QAED,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,MAA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,CAAA;AAEtD,+BAAY,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAA","sourcesContent":["import { InfluxDB, FluxTableMetaData } from '@influxdata/influxdb-client'\nimport { VM } from 'vm2'\n\nimport { ConnectionManager, Context, TaskRegistry } from '@things-factory/integration-base'\n\nconst debug = require('debug')('things-factory:influxdb-query')\n\ninterface InfluxData {\n measurement: string\n tags: { [key: string]: string }\n fields: { [key: string]: number | string | boolean }\n timestamp: string\n}\n\ninterface InfluxRaw {\n _time: string\n _start: string\n _stop: string\n _measurement: string\n _field: string\n _value: any\n table: any\n result: any\n [tag: string]: string\n}\n\nfunction processInfluxData(raws: InfluxRaw[]): InfluxData[] {\n var current: InfluxData\n var result: { [time: string]: InfluxData } = {}\n\n raws.forEach(raw => {\n const { _time, _field, _value, _measurement, _start, _stop, result: _result, table, ...tags } = raw\n\n result[_time] ||= {\n timestamp: _time,\n measurement: _measurement,\n tags,\n fields: {}\n }\n\n result[_time].fields[_field] = _value\n })\n\n return Object.values(result)\n}\n\nasync function influxdbQuery(step, { domain, user, data, variables, lng }: Context) {\n const {\n connection,\n params: { organization, query }\n } = step\n\n const client = ConnectionManager.getConnectionInstanceByName(domain, connection) as InfluxDB\n if (!client) {\n debug(`no connection : ${connection}`)\n throw new Error(`no connection : ${connection}`)\n }\n\n const vm = new VM({\n sandbox: {\n domain,\n user,\n lng,\n data,\n variables\n }\n })\n\n const fluxQuery = vm.run('`' + query + '`')\n\n const queryApi = client.getQueryApi(organization)\n\n const result = await queryApi.collectRows(fluxQuery)\n\n return {\n data: processInfluxData(result as InfluxRaw[])\n }\n}\n\ninfluxdbQuery.parameterSpec = [\n {\n type: 'string',\n name: 'organization',\n label: 'influxdb.organization'\n },\n {\n type: 'textarea',\n name: 'query',\n label: 'influxdb.query'\n }\n]\n\ninfluxdbQuery.help = 'integration/task/influxdb-query'\n\nTaskRegistry.registerTaskHandler('influxdb-query', influxdbQuery)\n"]}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const influxdb_client_1 = require("@influxdata/influxdb-client");
4
+ const utils_1 = require("@things-factory/utils");
5
+ const integration_base_1 = require("@things-factory/integration-base");
6
+ const debug = require('debug')('things-factory:influxdb-write-point');
7
+ async function influxdbWritePoint(step, { logger, domain, data }) {
8
+ const { connection, params: { organization, bucket, measurement, scheme } } = step;
9
+ const client = integration_base_1.ConnectionManager.getConnectionInstanceByName(domain, connection);
10
+ if (!client) {
11
+ debug(`no connection : ${connection}`);
12
+ throw new Error(`no connection : ${connection}`);
13
+ }
14
+ const writeClient = client.getWriteApi(organization, bucket, 'ns');
15
+ const point = new influxdb_client_1.Point(measurement);
16
+ scheme.forEach((field) => {
17
+ const { name, val, type, accessor } = field;
18
+ const calculated = accessor ? (0, utils_1.access)(accessor, data) || val : val;
19
+ switch (type) {
20
+ case 'Tag':
21
+ point.tag(name, calculated);
22
+ break;
23
+ case 'String':
24
+ point.stringField(name, calculated);
25
+ break;
26
+ case 'Integer':
27
+ point.intField(name, calculated);
28
+ break;
29
+ case 'Unsigned':
30
+ point.uintField(name, calculated);
31
+ break;
32
+ case 'Float':
33
+ point.floatField(name, calculated);
34
+ break;
35
+ case 'Boolean':
36
+ point.booleanField(name, calculated);
37
+ break;
38
+ }
39
+ });
40
+ await writeClient.writePoint(point);
41
+ await writeClient.close();
42
+ return {
43
+ data: point.fields
44
+ };
45
+ }
46
+ influxdbWritePoint.parameterSpec = [
47
+ {
48
+ type: 'string',
49
+ name: 'organization',
50
+ label: 'influxdb.organization'
51
+ },
52
+ {
53
+ type: 'string',
54
+ name: 'bucket',
55
+ label: 'influxdb.bucket'
56
+ },
57
+ {
58
+ type: 'string',
59
+ name: 'measurement',
60
+ label: 'influxdb.measurement'
61
+ },
62
+ {
63
+ type: 'influxdb-point-scheme',
64
+ name: 'scheme',
65
+ label: 'influxdb.point-scheme'
66
+ }
67
+ ];
68
+ influxdbWritePoint.help = 'integration/task/influxdb-write-point';
69
+ integration_base_1.TaskRegistry.registerTaskHandler('influxdb-write-point', influxdbWritePoint);
70
+ //# sourceMappingURL=influxdb-write-point.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"influxdb-write-point.js","sourceRoot":"","sources":["../../../server/engine/task/influxdb-write-point.ts"],"names":[],"mappings":";;AAAA,iEAAmD;AAEnD,iDAA8C;AAC9C,uEAAkF;AAElF,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,qCAAqC,CAAC,CAAA;AASrE,KAAK,UAAU,kBAAkB,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE;IAC9D,MAAM,EACJ,UAAU,EACV,MAAM,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,EACtD,GAAG,IAAI,CAAA;IAER,MAAM,MAAM,GAAG,oCAAiB,CAAC,2BAA2B,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IAChF,IAAI,CAAC,MAAM,EAAE;QACX,KAAK,CAAC,mBAAmB,UAAU,EAAE,CAAC,CAAA;QACtC,MAAM,IAAI,KAAK,CAAC,mBAAmB,UAAU,EAAE,CAAC,CAAA;KACjD;IAED,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;IAClE,MAAM,KAAK,GAAG,IAAI,uBAAK,CAAC,WAAW,CAAC,CAAA;IAEpC,MAAM,CAAC,OAAO,CAAC,CAAC,KAA0B,EAAE,EAAE;QAC5C,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAA;QAC3C,MAAM,UAAU,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAA,cAAM,EAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAA;QAEjE,QAAQ,IAAI,EAAE;YACZ,KAAK,KAAK;g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Content":["import { Point } from '@influxdata/influxdb-client'\n\nimport { access } from '@things-factory/utils'\nimport { ConnectionManager, TaskRegistry } from '@things-factory/integration-base'\n\nconst debug = require('debug')('things-factory:influxdb-write-point')\n\ntype InfluxDBPointScheme = {\n name: string\n type: string\n val?: any\n accessor?: string\n}\n\nasync function influxdbWritePoint(step, { logger, domain, data }) {\n const {\n connection,\n params: { organization, bucket, measurement, scheme }\n } = step\n\n const client = ConnectionManager.getConnectionInstanceByName(domain, connection)\n if (!client) {\n debug(`no connection : ${connection}`)\n throw new Error(`no connection : ${connection}`)\n }\n\n const writeClient = client.getWriteApi(organization, bucket, 'ns')\n const point = new Point(measurement)\n\n scheme.forEach((field: InfluxDBPointScheme) => {\n const { name, val, type, accessor } = field\n const calculated = accessor ? access(accessor, data) || val : val\n\n switch (type) {\n case 'Tag':\n point.tag(name, calculated)\n break\n case 'String':\n point.stringField(name, calculated)\n break\n case 'Integer':\n point.intField(name, calculated)\n break\n case 'Unsigned':\n point.uintField(name, calculated)\n break\n case 'Float':\n point.floatField(name, calculated)\n break\n case 'Boolean':\n point.booleanField(name, calculated)\n break\n }\n })\n\n await writeClient.writePoint(point)\n await writeClient.close()\n\n return {\n data: point.fields\n }\n}\n\ninfluxdbWritePoint.parameterSpec = [\n {\n type: 'string',\n name: 'organization',\n label: 'influxdb.organization'\n },\n {\n type: 'string',\n name: 'bucket',\n label: 'influxdb.bucket'\n },\n {\n type: 'string',\n name: 'measurement',\n label: 'influxdb.measurement'\n },\n {\n type: 'influxdb-point-scheme',\n name: 'scheme',\n label: 'influxdb.point-scheme'\n }\n]\n\ninfluxdbWritePoint.help = 'integration/task/influxdb-write-point'\n\nTaskRegistry.registerTaskHandler('influxdb-write-point', influxdbWritePoint)\n"]}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("./engine");
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;AAAA,oBAAiB","sourcesContent":["import './engine'\n"]}