influx 5.7.0 → 5.9.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.
@@ -27,6 +27,11 @@ jobs:
27
27
  - name: Checkout
28
28
  uses: actions/checkout@v2
29
29
 
30
+ - name: Reconfigure Git to use HTTP authentication
31
+ run: >
32
+ git config --global url."https://github.com/".insteadOf
33
+ ssh://git@github.com/
34
+
30
35
  - name: Setup Node.js
31
36
  uses: actions/setup-node@v2
32
37
  with:
@@ -36,7 +41,7 @@ jobs:
36
41
  run: npm ci
37
42
 
38
43
  - name: Run InfluxDB
39
- run: docker run -d -p 8083:8083 -p 8086:8086 influxdb
44
+ run: docker run -d -p 8083:8083 -p 8086:8086 influxdb:1.8
40
45
 
41
46
  - name: Run tests in browser
42
47
  run: npm run test:browser
@@ -54,6 +59,11 @@ jobs:
54
59
  - name: Checkout
55
60
  uses: actions/checkout@v2
56
61
 
62
+ - name: Reconfigure Git to use HTTP authentication
63
+ run: >
64
+ git config --global url."https://github.com/".insteadOf
65
+ ssh://git@github.com/
66
+
57
67
  - name: Setup node ${{ matrix.node }}
58
68
  uses: actions/setup-node@v2
59
69
  with:
@@ -63,7 +73,7 @@ jobs:
63
73
  run: npm ci
64
74
 
65
75
  - name: Run InfluxDB
66
- run: docker run -d -p 8083:8083 -p 8086:8086 influxdb
76
+ run: docker run -d -p 8083:8083 -p 8086:8086 influxdb:1.8
67
77
 
68
78
  - name: Run tests
69
79
  run: npm run test:ci
@@ -72,4 +82,3 @@ jobs:
72
82
  uses: coverallsapp/github-action@v1.1.2
73
83
  with:
74
84
  github-token: ${{ secrets.GITHUB_TOKEN }}
75
-
@@ -7,11 +7,16 @@ jobs:
7
7
  release:
8
8
  name: Release
9
9
  runs-on: ubuntu-18.04
10
+ if: github.repository == 'node-influx/node-influx'
10
11
  steps:
11
12
  - name: Checkout
12
13
  uses: actions/checkout@v2
13
14
  with:
14
15
  fetch-depth: 0
16
+ - name: Reconfigure Git to use HTTP authentication
17
+ run: >
18
+ git config --global url."https://github.com/".insteadOf
19
+ ssh://git@github.com/
15
20
  - name: Setup Node.js
16
21
  uses: actions/setup-node@v2
17
22
  with:
@@ -22,4 +27,4 @@ jobs:
22
27
  env:
23
28
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24
29
  NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
25
- run: npm run clean && npm run build:dist && npx semantic-release
30
+ run: npm run clean && npm run build:dist && npx semantic-release
package/README.md CHANGED
@@ -9,9 +9,9 @@
9
9
  </p>
10
10
 
11
11
  <p align="center">
12
- <a href="https://travis-ci.org/node-influx/node-influx">
13
- <img src="https://img.shields.io/travis/node-influx/node-influx/master.svg?style=flat-square"
14
- alt="Travis Build">
12
+ <a href="https://github.com/node-influx/node-influx/actions">
13
+ <img src="https://img.shields.io/github/workflow/status/node-influx/node-influx/CI/master?style=flat-square"
14
+ alt="CI Status">
15
15
  </a>
16
16
  <a href="">
17
17
  <img alt="Coveralls github branch" src="https://img.shields.io/coveralls/github/node-influx/node-influx/master.svg?style=flat-square">
@@ -27,6 +27,10 @@
27
27
  </a>
28
28
  </p>
29
29
 
30
+ # InfluxDB v1.x JavaScript library
31
+
32
+ Node and browser library for InfluxDB v1.x and older. For v2, please use the [official client](https://github.com/influxdata/influxdb-client-js/).
33
+
30
34
  <hr/>
31
35
 
32
36
  ## Installation
@@ -105,6 +105,21 @@ export interface IPoint {
105
105
  */
106
106
  timestamp?: Date | string | number;
107
107
  }
108
+ export interface IParsedPoint extends IPoint {
109
+ /**
110
+ * Fields Pairs is the list of key/value pairs for each field on the point
111
+ */
112
+ fieldsPairs: Array<[string, string]>;
113
+ /**
114
+ * Tags Names is the list of tag names in the point
115
+ */
116
+ tagsNames: string[];
117
+ /**
118
+ * Casted Timestamp is the timestamp value after being casted to the
119
+ * desired precision. Default 'n'
120
+ */
121
+ castedTimestamp?: string;
122
+ }
108
123
  export interface IWriteOptions {
109
124
  /**
110
125
  * Precision at which the points are written, defaults to nanoseconds 'n'.
@@ -141,7 +156,18 @@ export interface IQueryOptions {
141
156
  * Any placeholders used by the query. Using these is strongly recommended
142
157
  * to avoid injection attacks.
143
158
  */
144
- placeholders?: Record<string, string>;
159
+ placeholders?: Record<string, string | number>;
160
+ }
161
+ export interface IParseOptions {
162
+ /**
163
+ * Precision at which the points are written, defaults to nanoseconds 'n'.
164
+ */
165
+ precision?: grammar.TimePrecision;
166
+ /**
167
+ * Database under which to write the points. This is required if a default
168
+ * database is not provided in Influx.
169
+ */
170
+ database?: string;
145
171
  }
146
172
  /**
147
173
  * IRetentionOptions are passed into passed into the {@link
@@ -674,6 +700,52 @@ export declare class InfluxDB {
674
700
  * })
675
701
  */
676
702
  writePoints(points: IPoint[], options?: IWriteOptions): Promise<void>;
703
+ /**
704
+ * ParsePoint will perform the coercions/schema checks and return the data
705
+ * required for writing a point. This will throw an error if a schema check
706
+ * or coercion fails. This can be useful for flagging or "throwing out" bad
707
+ * points in a batch write to prevent the entire batch from getting aborted
708
+ *
709
+ * ---
710
+ *
711
+ * A note when using this function, {@link InfluxDB#writePoints} will still perform
712
+ * the same checks, so any pre-processed data will be checked for validity twice which
713
+ * has potential performance implications on large data sets
714
+ *
715
+ * @param point
716
+ * @param [options]
717
+ * @return
718
+ * @example
719
+ * // parse a point as if it is getting written to the default
720
+ * // databse with the default time precision
721
+ * influx.parsePoint({
722
+ * measurement: 'perf',
723
+ * tags: { host: 'box1.example.com' },
724
+ * fields: { cpu: getCpuUsage(), mem: getMemUsage() },
725
+ * })
726
+ *
727
+ * // you can manually specify the database and time precision
728
+ * influx.parsePoint({
729
+ * measurement: 'perf',
730
+ * tags: { host: 'box1.example.com' },
731
+ * fields: { cpu: getCpuUsage(), mem: getMemUsage() },
732
+ * }, {
733
+ * precision: 's',
734
+ * database: 'my_db'
735
+ * })
736
+ *
737
+ * // if an error occurs, you can catch the error with try...catch
738
+ * try {
739
+ * influx.parsePoint({
740
+ * measurement: 'perf',
741
+ * tags: { host: 'box1.example.com', myExtraneousTag: 'value' },
742
+ * fields: { cpu: getCpuUsage(), mem: getMemUsage(), myExtraneousField: 'value' },
743
+ * })
744
+ * } catch(err) {
745
+ * handleError(err);
746
+ * }
747
+ */
748
+ parsePoint(point: IPoint, options?: IParseOptions): IParsedPoint;
677
749
  /**
678
750
  * WriteMeasurement functions similarly to {@link InfluxDB#writePoints}, but
679
751
  * it automatically fills in the `measurement` value for all points for you.
package/lib/src/index.js CHANGED
@@ -831,12 +831,7 @@ class InfluxDB {
831
831
  const { database = this._defaultDB(), precision = "n", retentionPolicy, } = options;
832
832
  let payload = "";
833
833
  points.forEach((point) => {
834
- const { fields = {}, tags = {}, measurement, timestamp } = point;
835
- const schema = this._schema[database] && this._schema[database][measurement];
836
- const fieldsPairs = schema
837
- ? schema.coerceFields(fields)
838
- : schema_1.coerceBadly(fields);
839
- const tagsNames = schema ? schema.checkTags(tags) : Object.keys(tags);
834
+ const { measurement, tags, fieldsPairs, tagsNames, castedTimestamp } = this.parsePoint(point, { database, precision });
840
835
  payload += (payload.length > 0 ? "\n" : "") + measurement;
841
836
  for (let tagsName of tagsNames) {
842
837
  payload +=
@@ -852,8 +847,8 @@ class InfluxDB {
852
847
  "=" +
853
848
  fieldsPairs[i][1];
854
849
  }
855
- if (timestamp !== undefined) {
856
- payload += " " + grammar.castTimestamp(timestamp, precision);
850
+ if (castedTimestamp !== undefined) {
851
+ payload += " " + castedTimestamp;
857
852
  }
858
853
  });
859
854
  return this._pool.discard({
@@ -869,6 +864,70 @@ class InfluxDB {
869
864
  },
870
865
  });
871
866
  }
867
+ /**
868
+ * ParsePoint will perform the coercions/schema checks and return the data
869
+ * required for writing a point. This will throw an error if a schema check
870
+ * or coercion fails. This can be useful for flagging or "throwing out" bad
871
+ * points in a batch write to prevent the entire batch from getting aborted
872
+ *
873
+ * ---
874
+ *
875
+ * A note when using this function, {@link InfluxDB#writePoints} will still perform
876
+ * the same checks, so any pre-processed data will be checked for validity twice which
877
+ * has potential performance implications on large data sets
878
+ *
879
+ * @param point
880
+ * @param [options]
881
+ * @return
882
+ * @example
883
+ * // parse a point as if it is getting written to the default
884
+ * // databse with the default time precision
885
+ * influx.parsePoint({
886
+ * measurement: 'perf',
887
+ * tags: { host: 'box1.example.com' },
888
+ * fields: { cpu: getCpuUsage(), mem: getMemUsage() },
889
+ * })
890
+ *
891
+ * // you can manually specify the database and time precision
892
+ * influx.parsePoint({
893
+ * measurement: 'perf',
894
+ * tags: { host: 'box1.example.com' },
895
+ * fields: { cpu: getCpuUsage(), mem: getMemUsage() },
896
+ * }, {
897
+ * precision: 's',
898
+ * database: 'my_db'
899
+ * })
900
+ *
901
+ * // if an error occurs, you can catch the error with try...catch
902
+ * try {
903
+ * influx.parsePoint({
904
+ * measurement: 'perf',
905
+ * tags: { host: 'box1.example.com', myExtraneousTag: 'value' },
906
+ * fields: { cpu: getCpuUsage(), mem: getMemUsage(), myExtraneousField: 'value' },
907
+ * })
908
+ * } catch(err) {
909
+ * handleError(err);
910
+ * }
911
+ */
912
+ parsePoint(point, options = {}) {
913
+ const { database = this._defaultDB(), precision = "n" } = options;
914
+ const { fields = {}, tags = {}, measurement, timestamp } = point;
915
+ const schema = this._schema[database] && this._schema[database][measurement];
916
+ const fieldsPairs = schema
917
+ ? schema.coerceFields(fields)
918
+ : schema_1.coerceBadly(fields);
919
+ const tagsNames = schema ? schema.checkTags(tags) : Object.keys(tags);
920
+ const castedTimestamp = timestamp && grammar.castTimestamp(timestamp, precision);
921
+ return {
922
+ fields,
923
+ tags,
924
+ measurement,
925
+ timestamp,
926
+ fieldsPairs,
927
+ tagsNames,
928
+ castedTimestamp,
929
+ };
930
+ }
872
931
  /**
873
932
  * WriteMeasurement functions similarly to {@link InfluxDB#writePoints}, but
874
933
  * it automatically fills in the `measurement` value for all points for you.
@@ -938,7 +997,7 @@ class InfluxDB {
938
997
  epoch: options.precision,
939
998
  q: query,
940
999
  rp: retentionPolicy,
941
- params: placeholders,
1000
+ params: JSON.stringify(placeholders),
942
1001
  }));
943
1002
  }
944
1003
  /**
@@ -957,7 +1016,11 @@ class InfluxDB {
957
1016
  * })
958
1017
  */
959
1018
  ping(timeout) {
960
- return this._pool.ping(timeout);
1019
+ let auth = undefined;
1020
+ if (typeof this._options.username === "string") {
1021
+ auth = `${this._options.username}:${this._options.password || ""}`;
1022
+ }
1023
+ return this._pool.ping(timeout, "/ping", auth);
961
1024
  }
962
1025
  /**
963
1026
  * Returns the default database that queries operates on. It throws if called
package/lib/src/pool.d.ts CHANGED
@@ -124,7 +124,7 @@ export declare class Pool {
124
124
  * Ping sends out a request to all available Influx servers, reporting on
125
125
  * their response time and version number.
126
126
  */
127
- ping(timeout: number, path?: string): Promise<IPingStats[]>;
127
+ ping(timeout: number, path?: string, auth?: string | undefined): Promise<IPingStats[]>;
128
128
  /**
129
129
  * Makes a request and calls back with the IncomingMessage stream,
130
130
  * if possible. An error is returned on a non-2xx status code.
package/lib/src/pool.js CHANGED
@@ -178,7 +178,7 @@ class Pool {
178
178
  * Ping sends out a request to all available Influx servers, reporting on
179
179
  * their response time and version number.
180
180
  */
181
- ping(timeout, path = "/ping") {
181
+ ping(timeout, path = "/ping", auth = undefined) {
182
182
  const todo = [];
183
183
  setToArray(this._hostsAvailable)
184
184
  .concat(setToArray(this._hostsDisabled))
@@ -187,7 +187,12 @@ class Pool {
187
187
  const url = host.url;
188
188
  const once = doOnce();
189
189
  return todo.push(new Promise((resolve) => {
190
- const req = request(Object.assign({ hostname: url.hostname, method: "GET", path, port: Number(url.port), protocol: url.protocol, timeout }, host.options), once((res) => {
190
+ const headers = {};
191
+ if (typeof auth !== "undefined") {
192
+ const encodedAuth = Buffer.from(auth).toString("base64");
193
+ headers["Authorization"] = `Basic ${encodedAuth}`;
194
+ }
195
+ const req = request(Object.assign({ hostname: url.hostname, method: "GET", path, port: Number(url.port), protocol: url.protocol, timeout, headers: headers }, host.options), once((res) => {
191
196
  resolve({
192
197
  url,
193
198
  res: res.resume(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "influx",
3
- "version": "5.7.0",
3
+ "version": "5.9.2",
4
4
  "description": "InfluxDB Client",
5
5
  "main": "./lib/src/index.js",
6
6
  "typings": "./lib/src/index",
@@ -44,36 +44,35 @@
44
44
  "@types/freeport": "1.0.21",
45
45
  "@types/mocha": "^8.0.0",
46
46
  "@types/node": "^14.0.24",
47
- "@types/sinon": "^9.0.4",
47
+ "@types/sinon": "^10.0.0",
48
48
  "@types/sinon-chai": "^3.2.4",
49
49
  "awesome-typescript-loader": "5.2.1",
50
- "chai": "4.2.0",
50
+ "chai": "4.3.4",
51
51
  "coveralls": "^3.1.0",
52
52
  "esdoc": "1.1.0",
53
53
  "esdoc-standard-plugin": "1.0.0",
54
54
  "freeport": "1.0.5",
55
55
  "istanbul": "0.4.5",
56
56
  "json-loader": "0.5.7",
57
- "karma": "^6.0.0",
57
+ "karma": "^6.3.2",
58
58
  "karma-chrome-launcher": "^3.1.0",
59
59
  "karma-mocha": "^2.0.1",
60
60
  "karma-mocha-reporter": "2.2.5",
61
61
  "karma-sourcemap-loader": "0.3.8",
62
62
  "karma-webpack": "^5.0.0-alpha.5",
63
- "lodash": "4.17.20",
63
+ "lodash": "4.17.21",
64
64
  "mocha": "^8.2.1",
65
65
  "node-fetch": "2.6.1",
66
66
  "npm-run-all": "4.1.5",
67
67
  "open-cli": "^6.0.1",
68
- "prettier": "^2.0.5",
69
- "puppeteer": "^5.5.0",
70
- "semantic-release": "^17.1.1",
71
- "sinon": "^9.0.2",
68
+ "prettier": "^2.3.0",
69
+ "puppeteer": "^10.0.0",
70
+ "semantic-release": "^17.4.2",
71
+ "sinon": "^11.0.0",
72
72
  "sinon-chai": "^3.5.0",
73
73
  "stream-http": "github:node-influx/stream-http",
74
- "ts-node": "^9.0.0",
75
- "typescript": "^4.0.0",
74
+ "ts-node": "^10.0.0",
75
+ "typescript": "^4.0.2",
76
76
  "webpack": "^4.43.0"
77
- },
78
- "dependencies": {}
77
+ }
79
78
  }