Added toJSON method to Connection class (#849)

* Added toJSON method to Connection class

* Updated test

* Updated typings
This commit is contained in:
Tomas Della Vedova
2019-05-14 12:00:27 -04:00
committed by delvedor
parent 3e9ae8b29c
commit 96a103b305
3 changed files with 27 additions and 0 deletions

1
lib/Connection.d.ts vendored
View File

@ -78,6 +78,7 @@ export default class Connection {
buildRequestObject(params: any): http.ClientRequestArgs;
// @ts-ignore
[inspect.custom](object: any, options: InspectOptions): string;
toJSON(): any;
}
export {};

View File

@ -239,6 +239,19 @@ class Connection {
roles: this.roles
}
}
toJSON () {
return {
url: this.url,
id: this.id,
headers: this.headers,
deadCount: this.deadCount,
resurrectTimeout: this.resurrectTimeout,
_openRequests: this._openRequests,
status: this.status,
roles: this.roles
}
}
}
Connection.statuses = {

View File

@ -794,3 +794,16 @@ test('Port handling', t => {
t.end()
})
test('Should not add agent and ssl to the serialized connection', t => {
const connection = new Connection({
url: new URL('http://localhost:9200')
})
t.strictEqual(
JSON.stringify(connection),
'{"url":"http://localhost:9200/","id":"http://localhost:9200/","headers":null,"deadCount":0,"resurrectTimeout":0,"_openRequests":0,"status":"alive","roles":{"master":true,"data":true,"ingest":true,"ml":false}}'
)
t.end()
})