influx 5.0.3 → 5.0.7

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.
@@ -1,365 +1,366 @@
1
- "use strict";
2
- var grammar_1 = require('./grammar');
3
- function regexHasFlags(re) {
4
- if (typeof re.flags !== 'undefined') {
5
- return re.flags.length > 0;
6
- }
7
- return !(/\/$/).test(re.toString());
8
- }
9
- /**
10
- * Expression is used to build filtering expressions, like those used in WHERE
11
- * clauses. It can be used for fluent and safe building of queries using
12
- * untrusted input.
13
- *
14
- * @example
15
- * e => e
16
- * .field('host').equals.value('ares.peet.io')
17
- * .or
18
- * .field('host').matches(/example\.com$/)
19
- * .or
20
- * .expr(e => e
21
- * .field('country').equals.value('US')
22
- * .and
23
- * .field('state').equals.value('WA'));
24
- *
25
- * // Generates:
26
- * // "host" = 'ares.peet.io' OR "host" ~= /example\.com$/ OR \
27
- * // ("county" = 'US' AND "state" = 'WA')
28
- */
29
- var Expression = (function () {
30
- function Expression() {
31
- this.query = [];
32
- }
33
- /**
34
- * Inserts a tag reference into the expression; the name will be
35
- * automatically escaped.
36
- * @param {String} name
37
- * @return {Expression}
38
- */
39
- Expression.prototype.tag = function (name) {
40
- this.field(name);
41
- return this;
42
- };
43
- /**
44
- * Inserts a field reference into the expression; the name will be
45
- * automatically escaped.
46
- * @param {String} name
47
- * @return {Expression}
48
- */
49
- Expression.prototype.field = function (name) {
50
- this.query.push(grammar_1.escape.quoted(name));
51
- return this;
52
- };
53
- /**
54
- * Inserts a subexpression; invokes the function with a new expression
55
- * that can be chained on.
56
- * @param {function(e: Expression): Expression} fn
57
- * @return {Expression}
58
- * @example
59
- * e.field('a').equals.value('b')
60
- * .or.expr(e =>
61
- * e.field('b').equals.value('b')
62
- * .and.field('a').equals.value('c'))
63
- * .toString()
64
- * // "a" = 'b' OR ("b" = 'b' AND "a" = 'c')
65
- */
66
- Expression.prototype.exp = function (fn) {
67
- this.query.push('(' + fn(new Expression()).toString() + ')');
68
- return this;
69
- };
70
- /**
71
- * Value chains on a value to the expression.
72
- *
73
- * - Numbers will be inserted verbatim
74
- * - Strings will be escaped and inserted
75
- * - Booleans will be inserted correctly
76
- * - Dates will be formatted and inserted correctly, including INanoDates.
77
- * - Regular expressions will be inserted correctly, however an error will
78
- * be thrown if they contain flags, as regex flags do not work in Influx
79
- * - Otherwise we'll try to call `.toString()` on the value, throwing
80
- * if we cannot do so.
81
- *
82
- * @param {*} value
83
- * @return {Expression}
84
- */
85
- Expression.prototype.value = function (value) {
86
- switch (typeof value) {
87
- case 'number':
88
- this.query.push(value);
89
- return this;
90
- case 'string':
91
- this.query.push(grammar_1.escape.stringLit(value));
92
- return this;
93
- case 'boolean':
94
- this.query.push(value ? 'TRUE' : 'FALSE');
95
- return this;
96
- default:
97
- if (value instanceof Date) {
98
- this.query.push(grammar_1.formatDate(value));
99
- return this;
100
- }
101
- if (value instanceof RegExp) {
102
- if (regexHasFlags(value)) {
103
- throw new Error('Attempted to query using a regex with flags, ' +
104
- 'but Influx doesn\'t support flags in queries.');
105
- }
106
- this.query.push('/' + value.source + '/');
107
- return this;
108
- }
109
- if (value && typeof value.toString === 'function') {
110
- this.query.push(value.toString());
111
- return this;
112
- }
113
- throw new Error("node-influx doesn't know how to encode the provided value into a " +
114
- 'query. If you think this is a bug, open an issue here: https://git.io/influx-err');
115
- }
116
- };
117
- Object.defineProperty(Expression.prototype, "and", {
118
- /**
119
- * Chains on an AND clause to the expression.
120
- * @type {Expression}
121
- */
122
- get: function () {
123
- this.query.push('AND');
124
- return this;
125
- },
126
- enumerable: true,
127
- configurable: true
128
- });
129
- Object.defineProperty(Expression.prototype, "or", {
130
- /**
131
- * Chains on an OR clause to the expression.
132
- * @type {Expression}
133
- */
134
- get: function () {
135
- this.query.push('OR');
136
- return this;
137
- },
138
- enumerable: true,
139
- configurable: true
140
- });
141
- Object.defineProperty(Expression.prototype, "plus", {
142
- /**
143
- * Chains on a `+` operator to the expression.
144
- * @type {Expression}
145
- */
146
- get: function () {
147
- this.query.push('+');
148
- return this;
149
- },
150
- enumerable: true,
151
- configurable: true
152
- });
153
- Object.defineProperty(Expression.prototype, "times", {
154
- /**
155
- * Chains on a `*` operator to the expression.
156
- * @type {Expression}
157
- */
158
- get: function () {
159
- this.query.push('*');
160
- return this;
161
- },
162
- enumerable: true,
163
- configurable: true
164
- });
165
- Object.defineProperty(Expression.prototype, "minus", {
166
- /**
167
- * Chains on a `-` operator to the expression.
168
- * @type {Expression}
169
- */
170
- get: function () {
171
- this.query.push('-');
172
- return this;
173
- },
174
- enumerable: true,
175
- configurable: true
176
- });
177
- Object.defineProperty(Expression.prototype, "div", {
178
- /**
179
- * Chains on a `/` operator to the expression.
180
- * @type {Expression}
181
- */
182
- get: function () {
183
- this.query.push('/');
184
- return this;
185
- },
186
- enumerable: true,
187
- configurable: true
188
- });
189
- Object.defineProperty(Expression.prototype, "equals", {
190
- /**
191
- * Chains on a `=` conditional to the expression.
192
- * @type {Expression}
193
- */
194
- get: function () {
195
- this.query.push('=');
196
- return this;
197
- },
198
- enumerable: true,
199
- configurable: true
200
- });
201
- Object.defineProperty(Expression.prototype, "matches", {
202
- /**
203
- * Chains on a `=~` conditional to the expression to match regexes.
204
- * @type {Expression}
205
- */
206
- get: function () {
207
- this.query.push('=~');
208
- return this;
209
- },
210
- enumerable: true,
211
- configurable: true
212
- });
213
- Object.defineProperty(Expression.prototype, "doesntMatch", {
214
- /**
215
- * Chains on a `!`` conditional to the expression to match regexes.
216
- * @type {Expression}
217
- */
218
- get: function () {
219
- this.query.push('!~');
220
- return this;
221
- },
222
- enumerable: true,
223
- configurable: true
224
- });
225
- Object.defineProperty(Expression.prototype, "notEqual", {
226
- /**
227
- * Chains on a `!=` conditional to the expression.
228
- * @type {Expression}
229
- */
230
- get: function () {
231
- this.query.push('!=');
232
- return this;
233
- },
234
- enumerable: true,
235
- configurable: true
236
- });
237
- Object.defineProperty(Expression.prototype, "gt", {
238
- /**
239
- * Chains on a `>` conditional to the expression.
240
- * @type {Expression}
241
- */
242
- get: function () {
243
- this.query.push('>');
244
- return this;
245
- },
246
- enumerable: true,
247
- configurable: true
248
- });
249
- Object.defineProperty(Expression.prototype, "gte", {
250
- /**
251
- * Chains on a `>=` conditional to the expression.
252
- * @type {Expression}
253
- */
254
- get: function () {
255
- this.query.push('>=');
256
- return this;
257
- },
258
- enumerable: true,
259
- configurable: true
260
- });
261
- Object.defineProperty(Expression.prototype, "lt", {
262
- /**
263
- * Chains on a `<` conditional to the expression.
264
- * @type {Expression}
265
- */
266
- get: function () {
267
- this.query.push('<');
268
- return this;
269
- },
270
- enumerable: true,
271
- configurable: true
272
- });
273
- Object.defineProperty(Expression.prototype, "lte", {
274
- /**
275
- * Chains on a `<=` conditional to the expression.
276
- * @type {Expression}
277
- */
278
- get: function () {
279
- this.query.push('<=');
280
- return this;
281
- },
282
- enumerable: true,
283
- configurable: true
284
- });
285
- /**
286
- * Converts the expression into its InfluxQL representation.
287
- * @return {String}
288
- */
289
- Expression.prototype.toString = function () {
290
- return this.query.join(' ');
291
- };
292
- return Expression;
293
- }());
294
- exports.Expression = Expression;
295
- /**
296
- * Measurement creates a reference to a particular measurement. You can
297
- * reference it solely by its name, but you can also specify the retention
298
- * policy and database it lives under.
299
- *
300
- * @example
301
- * m.name('my_measurement') // "my_measurement"
302
- * m.name('my_measurement').policy('one_day') // "one_day"."my_measurement"
303
- * m.name('my_measurement').policy('one_day').db('mydb') // "mydb".one_day"."my_measurement"
304
- */
305
- var Measurement = (function () {
306
- function Measurement() {
307
- this.parts = [null, null, null];
308
- }
309
- /**
310
- * Sets the measurement name.
311
- * @param {String} name
312
- * @return {Measurement}
313
- */
314
- Measurement.prototype.name = function (name) {
315
- this.parts[2] = name;
316
- return this;
317
- };
318
- /**
319
- * Sets the retention policy name.
320
- * @param {String} retentionPolicy
321
- * @return {Measurement}
322
- */
323
- Measurement.prototype.policy = function (retentionPolicy) {
324
- this.parts[1] = retentionPolicy;
325
- return this;
326
- };
327
- /**
328
- * Sets the database name.
329
- * @param {String} db
330
- * @return {Measurement}
331
- */
332
- Measurement.prototype.db = function (db) {
333
- this.parts[0] = db;
334
- return this;
335
- };
336
- /**
337
- * Converts the measurement into its InfluxQL representation.
338
- * @return {String}
339
- * @throws {Error} if a measurement name is not provided
340
- */
341
- Measurement.prototype.toString = function () {
342
- if (!this.parts[2]) {
343
- throw new Error("You must specify a measurement name to query! Got `" + this.parts[2] + "`");
344
- }
345
- return this.parts.filter(function (p) { return !!p; })
346
- .map(function (p) { return grammar_1.escape.quoted(p); })
347
- .join('.');
348
- };
349
- return Measurement;
350
- }());
351
- exports.Measurement = Measurement;
352
- function parseMeasurement(q) {
353
- if (typeof q.measurement === 'function') {
354
- return q.measurement(new Measurement()).toString();
355
- }
356
- return q.measurement;
357
- }
358
- exports.parseMeasurement = parseMeasurement;
359
- function parseWhere(q) {
360
- if (typeof q.where === 'function') {
361
- return q.where(new Expression()).toString();
362
- }
363
- return q.where;
364
- }
365
- exports.parseWhere = parseWhere;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var grammar_1 = require("./grammar");
4
+ function regexHasFlags(re) {
5
+ if (typeof re.flags !== 'undefined') {
6
+ return re.flags.length > 0;
7
+ }
8
+ return !(/\/$/).test(re.toString());
9
+ }
10
+ /**
11
+ * Expression is used to build filtering expressions, like those used in WHERE
12
+ * clauses. It can be used for fluent and safe building of queries using
13
+ * untrusted input.
14
+ *
15
+ * @example
16
+ * e => e
17
+ * .field('host').equals.value('ares.peet.io')
18
+ * .or
19
+ * .field('host').matches(/example\.com$/)
20
+ * .or
21
+ * .expr(e => e
22
+ * .field('country').equals.value('US')
23
+ * .and
24
+ * .field('state').equals.value('WA'));
25
+ *
26
+ * // Generates:
27
+ * // "host" = 'ares.peet.io' OR "host" ~= /example\.com$/ OR \
28
+ * // ("county" = 'US' AND "state" = 'WA')
29
+ */
30
+ var Expression = (function () {
31
+ function Expression() {
32
+ this.query = [];
33
+ }
34
+ /**
35
+ * Inserts a tag reference into the expression; the name will be
36
+ * automatically escaped.
37
+ * @param {String} name
38
+ * @return {Expression}
39
+ */
40
+ Expression.prototype.tag = function (name) {
41
+ this.field(name);
42
+ return this;
43
+ };
44
+ /**
45
+ * Inserts a field reference into the expression; the name will be
46
+ * automatically escaped.
47
+ * @param {String} name
48
+ * @return {Expression}
49
+ */
50
+ Expression.prototype.field = function (name) {
51
+ this.query.push(grammar_1.escape.quoted(name));
52
+ return this;
53
+ };
54
+ /**
55
+ * Inserts a subexpression; invokes the function with a new expression
56
+ * that can be chained on.
57
+ * @param {function(e: Expression): Expression} fn
58
+ * @return {Expression}
59
+ * @example
60
+ * e.field('a').equals.value('b')
61
+ * .or.expr(e =>
62
+ * e.field('b').equals.value('b')
63
+ * .and.field('a').equals.value('c'))
64
+ * .toString()
65
+ * // "a" = 'b' OR ("b" = 'b' AND "a" = 'c')
66
+ */
67
+ Expression.prototype.exp = function (fn) {
68
+ this.query.push('(' + fn(new Expression()).toString() + ')');
69
+ return this;
70
+ };
71
+ /**
72
+ * Value chains on a value to the expression.
73
+ *
74
+ * - Numbers will be inserted verbatim
75
+ * - Strings will be escaped and inserted
76
+ * - Booleans will be inserted correctly
77
+ * - Dates will be formatted and inserted correctly, including INanoDates.
78
+ * - Regular expressions will be inserted correctly, however an error will
79
+ * be thrown if they contain flags, as regex flags do not work in Influx
80
+ * - Otherwise we'll try to call `.toString()` on the value, throwing
81
+ * if we cannot do so.
82
+ *
83
+ * @param {*} value
84
+ * @return {Expression}
85
+ */
86
+ Expression.prototype.value = function (value) {
87
+ switch (typeof value) {
88
+ case 'number':
89
+ this.query.push(value);
90
+ return this;
91
+ case 'string':
92
+ this.query.push(grammar_1.escape.stringLit(value));
93
+ return this;
94
+ case 'boolean':
95
+ this.query.push(value ? 'TRUE' : 'FALSE');
96
+ return this;
97
+ default:
98
+ if (value instanceof Date) {
99
+ this.query.push(grammar_1.formatDate(value));
100
+ return this;
101
+ }
102
+ if (value instanceof RegExp) {
103
+ if (regexHasFlags(value)) {
104
+ throw new Error('Attempted to query using a regex with flags, ' +
105
+ 'but Influx doesn\'t support flags in queries.');
106
+ }
107
+ this.query.push('/' + value.source + '/');
108
+ return this;
109
+ }
110
+ if (value && typeof value.toString === 'function') {
111
+ this.query.push(value.toString());
112
+ return this;
113
+ }
114
+ throw new Error("node-influx doesn't know how to encode the provided value into a " +
115
+ 'query. If you think this is a bug, open an issue here: https://git.io/influx-err');
116
+ }
117
+ };
118
+ Object.defineProperty(Expression.prototype, "and", {
119
+ /**
120
+ * Chains on an AND clause to the expression.
121
+ * @type {Expression}
122
+ */
123
+ get: function () {
124
+ this.query.push('AND');
125
+ return this;
126
+ },
127
+ enumerable: true,
128
+ configurable: true
129
+ });
130
+ Object.defineProperty(Expression.prototype, "or", {
131
+ /**
132
+ * Chains on an OR clause to the expression.
133
+ * @type {Expression}
134
+ */
135
+ get: function () {
136
+ this.query.push('OR');
137
+ return this;
138
+ },
139
+ enumerable: true,
140
+ configurable: true
141
+ });
142
+ Object.defineProperty(Expression.prototype, "plus", {
143
+ /**
144
+ * Chains on a `+` operator to the expression.
145
+ * @type {Expression}
146
+ */
147
+ get: function () {
148
+ this.query.push('+');
149
+ return this;
150
+ },
151
+ enumerable: true,
152
+ configurable: true
153
+ });
154
+ Object.defineProperty(Expression.prototype, "times", {
155
+ /**
156
+ * Chains on a `*` operator to the expression.
157
+ * @type {Expression}
158
+ */
159
+ get: function () {
160
+ this.query.push('*');
161
+ return this;
162
+ },
163
+ enumerable: true,
164
+ configurable: true
165
+ });
166
+ Object.defineProperty(Expression.prototype, "minus", {
167
+ /**
168
+ * Chains on a `-` operator to the expression.
169
+ * @type {Expression}
170
+ */
171
+ get: function () {
172
+ this.query.push('-');
173
+ return this;
174
+ },
175
+ enumerable: true,
176
+ configurable: true
177
+ });
178
+ Object.defineProperty(Expression.prototype, "div", {
179
+ /**
180
+ * Chains on a `/` operator to the expression.
181
+ * @type {Expression}
182
+ */
183
+ get: function () {
184
+ this.query.push('/');
185
+ return this;
186
+ },
187
+ enumerable: true,
188
+ configurable: true
189
+ });
190
+ Object.defineProperty(Expression.prototype, "equals", {
191
+ /**
192
+ * Chains on a `=` conditional to the expression.
193
+ * @type {Expression}
194
+ */
195
+ get: function () {
196
+ this.query.push('=');
197
+ return this;
198
+ },
199
+ enumerable: true,
200
+ configurable: true
201
+ });
202
+ Object.defineProperty(Expression.prototype, "matches", {
203
+ /**
204
+ * Chains on a `=~` conditional to the expression to match regexes.
205
+ * @type {Expression}
206
+ */
207
+ get: function () {
208
+ this.query.push('=~');
209
+ return this;
210
+ },
211
+ enumerable: true,
212
+ configurable: true
213
+ });
214
+ Object.defineProperty(Expression.prototype, "doesntMatch", {
215
+ /**
216
+ * Chains on a `!`` conditional to the expression to match regexes.
217
+ * @type {Expression}
218
+ */
219
+ get: function () {
220
+ this.query.push('!~');
221
+ return this;
222
+ },
223
+ enumerable: true,
224
+ configurable: true
225
+ });
226
+ Object.defineProperty(Expression.prototype, "notEqual", {
227
+ /**
228
+ * Chains on a `!=` conditional to the expression.
229
+ * @type {Expression}
230
+ */
231
+ get: function () {
232
+ this.query.push('!=');
233
+ return this;
234
+ },
235
+ enumerable: true,
236
+ configurable: true
237
+ });
238
+ Object.defineProperty(Expression.prototype, "gt", {
239
+ /**
240
+ * Chains on a `>` conditional to the expression.
241
+ * @type {Expression}
242
+ */
243
+ get: function () {
244
+ this.query.push('>');
245
+ return this;
246
+ },
247
+ enumerable: true,
248
+ configurable: true
249
+ });
250
+ Object.defineProperty(Expression.prototype, "gte", {
251
+ /**
252
+ * Chains on a `>=` conditional to the expression.
253
+ * @type {Expression}
254
+ */
255
+ get: function () {
256
+ this.query.push('>=');
257
+ return this;
258
+ },
259
+ enumerable: true,
260
+ configurable: true
261
+ });
262
+ Object.defineProperty(Expression.prototype, "lt", {
263
+ /**
264
+ * Chains on a `<` conditional to the expression.
265
+ * @type {Expression}
266
+ */
267
+ get: function () {
268
+ this.query.push('<');
269
+ return this;
270
+ },
271
+ enumerable: true,
272
+ configurable: true
273
+ });
274
+ Object.defineProperty(Expression.prototype, "lte", {
275
+ /**
276
+ * Chains on a `<=` conditional to the expression.
277
+ * @type {Expression}
278
+ */
279
+ get: function () {
280
+ this.query.push('<=');
281
+ return this;
282
+ },
283
+ enumerable: true,
284
+ configurable: true
285
+ });
286
+ /**
287
+ * Converts the expression into its InfluxQL representation.
288
+ * @return {String}
289
+ */
290
+ Expression.prototype.toString = function () {
291
+ return this.query.join(' ');
292
+ };
293
+ return Expression;
294
+ }());
295
+ exports.Expression = Expression;
296
+ /**
297
+ * Measurement creates a reference to a particular measurement. You can
298
+ * reference it solely by its name, but you can also specify the retention
299
+ * policy and database it lives under.
300
+ *
301
+ * @example
302
+ * m.name('my_measurement') // "my_measurement"
303
+ * m.name('my_measurement').policy('one_day') // "one_day"."my_measurement"
304
+ * m.name('my_measurement').policy('one_day').db('mydb') // "mydb".one_day"."my_measurement"
305
+ */
306
+ var Measurement = (function () {
307
+ function Measurement() {
308
+ this.parts = [null, null, null];
309
+ }
310
+ /**
311
+ * Sets the measurement name.
312
+ * @param {String} name
313
+ * @return {Measurement}
314
+ */
315
+ Measurement.prototype.name = function (name) {
316
+ this.parts[2] = name;
317
+ return this;
318
+ };
319
+ /**
320
+ * Sets the retention policy name.
321
+ * @param {String} retentionPolicy
322
+ * @return {Measurement}
323
+ */
324
+ Measurement.prototype.policy = function (retentionPolicy) {
325
+ this.parts[1] = retentionPolicy;
326
+ return this;
327
+ };
328
+ /**
329
+ * Sets the database name.
330
+ * @param {String} db
331
+ * @return {Measurement}
332
+ */
333
+ Measurement.prototype.db = function (db) {
334
+ this.parts[0] = db;
335
+ return this;
336
+ };
337
+ /**
338
+ * Converts the measurement into its InfluxQL representation.
339
+ * @return {String}
340
+ * @throws {Error} if a measurement name is not provided
341
+ */
342
+ Measurement.prototype.toString = function () {
343
+ if (!this.parts[2]) {
344
+ throw new Error("You must specify a measurement name to query! Got `" + this.parts[2] + "`");
345
+ }
346
+ return this.parts.filter(function (p) { return !!p; })
347
+ .map(function (p) { return grammar_1.escape.quoted(p); })
348
+ .join('.');
349
+ };
350
+ return Measurement;
351
+ }());
352
+ exports.Measurement = Measurement;
353
+ function parseMeasurement(q) {
354
+ if (typeof q.measurement === 'function') {
355
+ return q.measurement(new Measurement()).toString();
356
+ }
357
+ return q.measurement;
358
+ }
359
+ exports.parseMeasurement = parseMeasurement;
360
+ function parseWhere(q) {
361
+ if (typeof q.where === 'function') {
362
+ return q.where(new Expression()).toString();
363
+ }
364
+ return q.where;
365
+ }
366
+ exports.parseWhere = parseWhere;