Skip to content

Commit 6d2cf48

Browse files
committed
feat: support add plugin function
1 parent 8f5012d commit 6d2cf48

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

lib/client.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,17 @@ class Client extends EventEmitter {
965965
addAlgorithm(type, fn) {
966966
return internal(this).influx.addAlgorithm(type, fn);
967967
}
968+
/**
969+
* Add plugin function
970+
* @param {Function} fn - plugin function
971+
* @since 2.11.0
972+
* @example
973+
* const noCache = require('superagent-no-cache')
974+
* client.addPlugin(noCache);
975+
*/
976+
addPlugin(fn) {
977+
return internal(this).influx.addPlugin(fn);
978+
}
968979
}
969980

970981
module.exports = Client;

lib/influx.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,14 @@ class Influx {
200200
addAlgorithm(type, fn) {
201201
return internal(this).client.addAlgorithm(type, fn);
202202
}
203+
204+
/**
205+
* Add plugin function
206+
* @param {Function} fn plugin function
207+
*/
208+
addPlugin(fn) {
209+
return internal(this).client.addPlugin(fn);
210+
}
203211
}
204212

205213
module.exports = Influx;

test/client.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,26 @@ describe('Client', () => {
506506
}).catch(done);
507507
});
508508

509+
it('get measurement', done => {
510+
let called = false;
511+
client.addPlugin((req) => {
512+
if (called) {
513+
return;
514+
}
515+
if (!req.backendServer) {
516+
done(new Error('the backend field is null'));
517+
}
518+
called = true;
519+
});
520+
client.query('http')
521+
.then(() => {
522+
if (!called) {
523+
done(new Error('not called'));
524+
}
525+
})
526+
.catch(done);
527+
});
528+
509529
it('drop database', function(done) {
510530
this.timeout(5000);
511531
client.stopHealthCheck();

0 commit comments

Comments
 (0)